This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
89 lines (79 loc) · 2.45 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* 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('tags')
const Settings = require('settings-sharelatex')
const logger = require('logger-sharelatex')
logger.initialize('tags')
const express = require('express')
const app = express()
const controller = require('./app/js/TagsController')
const Path = require('path')
metrics.memory.monitor(logger)
const HealthCheckController = require('./app/js/HealthCheckController')
app.configure(function() {
app.use(express.methodOverride())
app.use(express.bodyParser())
app.use(metrics.http.monitor(logger))
return app.use(express.errorHandler())
})
metrics.injectMetricsRoute(app)
app.get('/user/:user_id/tag', controller.getUserTags)
app.post('/user/:user_id/tag', controller.createTag)
app.put('/user/:user_id/tag', controller.updateTagUserIds)
app.post('/user/:user_id/tag/:tag_id/rename', controller.renameTag)
app.del('/user/:user_id/tag/:tag_id', controller.deleteTag)
app.post(
'/user/:user_id/tag/:tag_id/project/:project_id',
controller.addProjectToTag
)
app.post(
'/user/:user_id/tag/project/:project_id',
controller.addProjectToTagName
)
app.del(
'/user/:user_id/tag/:tag_id/project/:project_id',
controller.removeProjectFromTag
)
app.del(
'/user/:user_id/project/:project_id',
controller.removeProjectFromAllTags
)
app.get('/status', (req, res) => res.send('tags sharelatex up'))
app.get('/health_check', (req, res) =>
HealthCheckController.check(function(err) {
if (err != null) {
logger.err({ err }, 'error performing health check')
return res.send(500)
} else {
return res.send(200)
}
})
)
app.get('*', (req, res) => res.send(404))
const host =
__guard__(
Settings.internal != null ? Settings.internal.tags : undefined,
x => x.host
) || 'localhost'
const port =
__guard__(
Settings.internal != null ? Settings.internal.tags : undefined,
x1 => x1.port
) || 3012
module.exports = app
if (!module.parent) {
app.listen(port, host, () =>
logger.info(`tags starting up, listening on ${host}:${port}`)
)
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}