mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 23:27:13 +00:00
prettier: convert individual decaffeinated files to Prettier format
This commit is contained in:
parent
421d6dabab
commit
5bca0c9bab
2 changed files with 92 additions and 86 deletions
|
@ -4,83 +4,85 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const Metrics = require("metrics-sharelatex");
|
||||
Metrics.initialize("docstore");
|
||||
const Settings = require("settings-sharelatex");
|
||||
const logger = require("logger-sharelatex");
|
||||
const express = require("express");
|
||||
const bodyParser = require("body-parser");
|
||||
const Errors = require("./app/js/Errors");
|
||||
const HttpController = require("./app/js/HttpController");
|
||||
const Path = require("path");
|
||||
const Metrics = require('metrics-sharelatex')
|
||||
Metrics.initialize('docstore')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const logger = require('logger-sharelatex')
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const Errors = require('./app/js/Errors')
|
||||
const HttpController = require('./app/js/HttpController')
|
||||
const Path = require('path')
|
||||
|
||||
|
||||
logger.initialize("docstore");
|
||||
logger.initialize('docstore')
|
||||
if (Metrics.event_loop != null) {
|
||||
Metrics.event_loop.monitor(logger);
|
||||
Metrics.event_loop.monitor(logger)
|
||||
}
|
||||
|
||||
const app = express();
|
||||
const app = express()
|
||||
|
||||
app.use(Metrics.http.monitor(logger));
|
||||
app.use(Metrics.http.monitor(logger))
|
||||
|
||||
Metrics.injectMetricsRoute(app);
|
||||
Metrics.injectMetricsRoute(app)
|
||||
|
||||
app.param('project_id', function(req, res, next, project_id) {
|
||||
if ((project_id != null ? project_id.match(/^[0-9a-f]{24}$/) : undefined)) {
|
||||
return next();
|
||||
} else {
|
||||
return next(new Error("invalid project id"));
|
||||
}
|
||||
});
|
||||
if (project_id != null ? project_id.match(/^[0-9a-f]{24}$/) : undefined) {
|
||||
return next()
|
||||
} else {
|
||||
return next(new Error('invalid project id'))
|
||||
}
|
||||
})
|
||||
|
||||
app.param('doc_id', function(req, res, next, doc_id) {
|
||||
if ((doc_id != null ? doc_id.match(/^[0-9a-f]{24}$/) : undefined)) {
|
||||
return next();
|
||||
} else {
|
||||
return next(new Error("invalid doc id"));
|
||||
}
|
||||
});
|
||||
if (doc_id != null ? doc_id.match(/^[0-9a-f]{24}$/) : undefined) {
|
||||
return next()
|
||||
} else {
|
||||
return next(new Error('invalid doc id'))
|
||||
}
|
||||
})
|
||||
|
||||
Metrics.injectMetricsRoute(app);
|
||||
Metrics.injectMetricsRoute(app)
|
||||
|
||||
app.get('/project/:project_id/doc', HttpController.getAllDocs);
|
||||
app.get('/project/:project_id/ranges', HttpController.getAllRanges);
|
||||
app.get('/project/:project_id/doc/:doc_id', HttpController.getDoc);
|
||||
app.get('/project/:project_id/doc/:doc_id/raw', HttpController.getRawDoc);
|
||||
app.get('/project/:project_id/doc', HttpController.getAllDocs)
|
||||
app.get('/project/:project_id/ranges', HttpController.getAllRanges)
|
||||
app.get('/project/:project_id/doc/:doc_id', HttpController.getDoc)
|
||||
app.get('/project/:project_id/doc/:doc_id/raw', HttpController.getRawDoc)
|
||||
// Add 64kb overhead for the JSON encoding, and double the size to allow for ranges in the json payload
|
||||
app.post('/project/:project_id/doc/:doc_id', bodyParser.json({limit: (Settings.max_doc_length + (64 * 1024)) * 2}), HttpController.updateDoc);
|
||||
app.del('/project/:project_id/doc/:doc_id', HttpController.deleteDoc);
|
||||
app.post(
|
||||
'/project/:project_id/doc/:doc_id',
|
||||
bodyParser.json({ limit: (Settings.max_doc_length + 64 * 1024) * 2 }),
|
||||
HttpController.updateDoc
|
||||
)
|
||||
app.del('/project/:project_id/doc/:doc_id', HttpController.deleteDoc)
|
||||
|
||||
app.post('/project/:project_id/archive', HttpController.archiveAllDocs);
|
||||
app.post('/project/:project_id/unarchive', HttpController.unArchiveAllDocs);
|
||||
app.post('/project/:project_id/destroy', HttpController.destroyAllDocs);
|
||||
app.post('/project/:project_id/archive', HttpController.archiveAllDocs)
|
||||
app.post('/project/:project_id/unarchive', HttpController.unArchiveAllDocs)
|
||||
app.post('/project/:project_id/destroy', HttpController.destroyAllDocs)
|
||||
|
||||
app.get("/health_check", HttpController.healthCheck);
|
||||
app.get('/health_check', HttpController.healthCheck)
|
||||
|
||||
app.get('/status', (req, res) => res.send('docstore is alive'));
|
||||
app.get('/status', (req, res) => res.send('docstore is alive'))
|
||||
|
||||
app.use(function(error, req, res, next) {
|
||||
logger.error({err: error, req}, "request errored");
|
||||
if (error instanceof Errors.NotFoundError) {
|
||||
return res.send(404);
|
||||
} else {
|
||||
return res.send(500, "Oops, something went wrong");
|
||||
}
|
||||
});
|
||||
logger.error({ err: error, req }, 'request errored')
|
||||
if (error instanceof Errors.NotFoundError) {
|
||||
return res.send(404)
|
||||
} else {
|
||||
return res.send(500, 'Oops, something went wrong')
|
||||
}
|
||||
})
|
||||
|
||||
const {
|
||||
port
|
||||
} = Settings.internal.docstore;
|
||||
const {
|
||||
host
|
||||
} = Settings.internal.docstore;
|
||||
const { port } = Settings.internal.docstore
|
||||
const { host } = Settings.internal.docstore
|
||||
|
||||
if (!module.parent) { // Called directly
|
||||
app.listen(port, host, function(error) {
|
||||
if (error != null) { throw error; }
|
||||
return logger.info(`Docstore starting up, listening on ${host}:${port}`);
|
||||
});
|
||||
if (!module.parent) {
|
||||
// Called directly
|
||||
app.listen(port, host, function(error) {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
return logger.info(`Docstore starting up, listening on ${host}:${port}`)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = app;
|
||||
module.exports = app
|
||||
|
|
|
@ -3,42 +3,46 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const http = require('http');
|
||||
http.globalAgent.maxSockets = 300;
|
||||
const http = require('http')
|
||||
http.globalAgent.maxSockets = 300
|
||||
|
||||
const Settings = {
|
||||
internal: {
|
||||
docstore: {
|
||||
port: 3016,
|
||||
host: process.env['LISTEN_ADDRESS'] || "localhost"
|
||||
}
|
||||
},
|
||||
internal: {
|
||||
docstore: {
|
||||
port: 3016,
|
||||
host: process.env.LISTEN_ADDRESS || 'localhost'
|
||||
}
|
||||
},
|
||||
|
||||
mongo:{},
|
||||
mongo: {},
|
||||
|
||||
docstore: {
|
||||
healthCheck: {
|
||||
project_id: process.env['HEALTH_CHECK_PROJECT_ID']
|
||||
}
|
||||
},
|
||||
docstore: {
|
||||
healthCheck: {
|
||||
project_id: process.env.HEALTH_CHECK_PROJECT_ID
|
||||
}
|
||||
},
|
||||
|
||||
max_doc_length: 2 * 1024 * 1024 // 2mb
|
||||
};
|
||||
max_doc_length: 2 * 1024 * 1024 // 2mb
|
||||
}
|
||||
|
||||
if (process.env['MONGO_CONNECTION_STRING'] != null) {
|
||||
Settings.mongo.url = process.env['MONGO_CONNECTION_STRING'];
|
||||
} else if (process.env['MONGO_HOST'] != null) {
|
||||
Settings.mongo.url = `mongodb://${process.env['MONGO_HOST']}/sharelatex`;
|
||||
if (process.env.MONGO_CONNECTION_STRING != null) {
|
||||
Settings.mongo.url = process.env.MONGO_CONNECTION_STRING
|
||||
} else if (process.env.MONGO_HOST != null) {
|
||||
Settings.mongo.url = `mongodb://${process.env.MONGO_HOST}/sharelatex`
|
||||
} else {
|
||||
Settings.mongo.url = "mongodb://127.0.0.1/sharelatex";
|
||||
Settings.mongo.url = 'mongodb://127.0.0.1/sharelatex'
|
||||
}
|
||||
|
||||
if ((process.env['AWS_ACCESS_KEY_ID'] != null) && (process.env['AWS_SECRET_ACCESS_KEY'] != null) && (process.env['AWS_BUCKET'] != null)) {
|
||||
Settings.docstore.s3 = {
|
||||
key: process.env['AWS_ACCESS_KEY_ID'],
|
||||
secret: process.env['AWS_SECRET_ACCESS_KEY'],
|
||||
bucket: process.env['AWS_BUCKET']
|
||||
};
|
||||
if (
|
||||
process.env.AWS_ACCESS_KEY_ID != null &&
|
||||
process.env.AWS_SECRET_ACCESS_KEY != null &&
|
||||
process.env.AWS_BUCKET != null
|
||||
) {
|
||||
Settings.docstore.s3 = {
|
||||
key: process.env.AWS_ACCESS_KEY_ID,
|
||||
secret: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
bucket: process.env.AWS_BUCKET
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Settings;
|
||||
module.exports = Settings
|
||||
|
|
Loading…
Reference in a new issue