decaffeinate: convert individual files to js

This commit is contained in:
Tim Alby 2020-01-13 20:01:22 +01:00
parent 2eda6119c9
commit 30860286c3
2 changed files with 63 additions and 46 deletions

View file

@ -1,48 +1,60 @@
metrics = require("metrics-sharelatex") /*
metrics.initialize("notifications") * decaffeinate suggestions:
Settings = require 'settings-sharelatex' * DS102: Remove unnecessary code created because of implicit returns
logger = require 'logger-sharelatex' * DS103: Rewrite code to no longer use __guard__
logger.initialize("notifications-sharelatex") * DS207: Consider shorter variations of null checks
express = require('express') * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
app = express() */
controller = require("./app/js/NotificationsController") const metrics = require("metrics-sharelatex");
mongojs = require('mongojs') metrics.initialize("notifications");
db = mongojs(Settings.mongo.url, ['notifications']) const Settings = require('settings-sharelatex');
Path = require("path") const logger = require('logger-sharelatex');
logger.initialize("notifications-sharelatex");
const express = require('express');
const app = express();
const controller = require("./app/js/NotificationsController");
const mongojs = require('mongojs');
const db = mongojs(Settings.mongo.url, ['notifications']);
const Path = require("path");
metrics.memory.monitor(logger) metrics.memory.monitor(logger);
HealthCheckController = require("./app/js/HealthCheckController") const HealthCheckController = require("./app/js/HealthCheckController");
app.configure ()-> app.configure(function(){
app.use express.methodOverride() app.use(express.methodOverride());
app.use express.bodyParser() app.use(express.bodyParser());
app.use metrics.http.monitor(logger) app.use(metrics.http.monitor(logger));
app.use express.errorHandler() return app.use(express.errorHandler());
});
metrics.injectMetricsRoute(app) metrics.injectMetricsRoute(app);
app.post '/user/:user_id', controller.addNotification app.post('/user/:user_id', controller.addNotification);
app.get '/user/:user_id', controller.getUserNotifications app.get('/user/:user_id', controller.getUserNotifications);
app.del '/user/:user_id/notification/:notification_id', controller.removeNotificationId app.del('/user/:user_id/notification/:notification_id', controller.removeNotificationId);
app.del '/user/:user_id', controller.removeNotificationKey app.del('/user/:user_id', controller.removeNotificationKey);
app.del '/key/:key', controller.removeNotificationByKeyOnly app.del('/key/:key', controller.removeNotificationByKeyOnly);
app.get '/status', (req, res)-> app.get('/status', (req, res)=> res.send('notifications sharelatex up'));
res.send('notifications sharelatex up')
app.get '/health_check', (req, res)-> app.get('/health_check', (req, res)=>
HealthCheckController.check (err)-> HealthCheckController.check(function(err){
if err? if (err != null) {
logger.err err:err, "error performing health check" logger.err({err}, "error performing health check");
res.send 500 return res.send(500);
else } else {
res.send 200 return res.send(200);
}
})
);
app.get '*', (req, res)-> app.get('*', (req, res)=> res.send(404));
res.send 404
host = Settings.internal?.notifications?.host || "localhost" const host = __guard__(Settings.internal != null ? Settings.internal.notifications : undefined, x => x.host) || "localhost";
port = Settings.internal?.notifications?.port || 3042 const port = __guard__(Settings.internal != null ? Settings.internal.notifications : undefined, x1 => x1.port) || 3042;
app.listen port, host, -> app.listen(port, host, () => logger.info(`notifications starting up, listening on ${host}:${port}`));
logger.info "notifications starting up, listening on #{host}:#{port}"
function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
}

View file

@ -1,8 +1,13 @@
module.exports = Settings = let Settings;
internal: module.exports = (Settings = {
notifications: internal: {
port: 3042 notifications: {
host: process.env["LISTEN_ADDRESS"] or "localhost" port: 3042,
host: process.env["LISTEN_ADDRESS"] || "localhost"
}
},
mongo: mongo: {
url: process.env['MONGO_CONNECTION_STRING'] or "mongodb://#{process.env["MONGO_HOST"] or "localhost"}/sharelatex" url: process.env['MONGO_CONNECTION_STRING'] || `mongodb://${process.env["MONGO_HOST"] || "localhost"}/sharelatex`
}
});