overleaf/services/contacts/app.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-10 04:11:15 -05:00
Metrics = require "metrics-sharelatex"
Metrics.initialize("contacts")
Settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
express = require "express"
bodyParser = require "body-parser"
Errors = require "./app/js/Errors"
HttpController = require "./app/js/HttpController"
2019-01-10 04:11:15 -05:00
Path = require "path"
2019-01-10 04:11:15 -05:00
logger.initialize("contacts")
Metrics.event_loop?.monitor(logger)
app = express()
app.use Metrics.http.monitor(logger)
2019-01-10 04:11:15 -05:00
Metrics.injectMetricsRoute(app)
2015-10-07 09:20:30 -04:00
app.get '/user/:user_id/contacts', HttpController.getContacts
app.post '/user/:user_id/contacts', bodyParser.json(limit: "2mb"), HttpController.addContact
app.get '/status', (req, res)->
res.send('contacts is alive')
app.use (error, req, res, next) ->
logger.error err: error, "request errored"
if error instanceof Errors.NotFoundError
res.send 404
else
res.send(500, "Oops, something went wrong")
port = Settings.internal.contacts.port
host = Settings.internal.contacts.host
2018-05-23 06:01:07 -04:00
if !module.parent # Called directly
app.listen port, host, (error) ->
throw error if error?
logger.info "contacts starting up, listening on #{host}:#{port}"
module.exports = app