mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 21:34:53 -05:00
7f48c67512
* Add `unicorn/prefer-node-protocol` * Fix `unicorn/prefer-node-protocol` ESLint errors * Run `npm run format:fix` * Add sandboxed-module sourceTransformers in mocha setups Fix `no such file or directory, open 'node:fs'` in `sandboxed-module` * Remove `node:` in the SandboxedModule requires * Fix new linting errors with `node:` GitOrigin-RevId: 68f6e31e2191fcff4cb8058dd0a6914c14f59926
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import http from 'node:http'
|
|
import metrics from '@overleaf/metrics'
|
|
import logger from '@overleaf/logger'
|
|
import express from 'express'
|
|
import exegesisExpress from 'exegesis-express'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import * as messagesController from './Features/Messages/MessageHttpController.js'
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
logger.initialize('chat')
|
|
metrics.open_sockets.monitor()
|
|
|
|
metrics.leaked_sockets.monitor(logger)
|
|
|
|
export async function createServer() {
|
|
const app = express()
|
|
|
|
app.use(metrics.http.monitor(logger))
|
|
metrics.injectMetricsRoute(app)
|
|
|
|
// See https://github.com/exegesis-js/exegesis/blob/master/docs/Options.md
|
|
const options = {
|
|
controllers: { messagesController },
|
|
ignoreServers: true,
|
|
allowMissingControllers: false,
|
|
}
|
|
|
|
// const exegesisMiddleware = await exegesisExpress.middleware(
|
|
const exegesisMiddleware = await exegesisExpress.middleware(
|
|
path.resolve(__dirname, '../../chat.yaml'),
|
|
options
|
|
)
|
|
|
|
// If you have any body parsers, this should go before them.
|
|
app.use(exegesisMiddleware)
|
|
|
|
// Return a 404
|
|
app.use((req, res) => {
|
|
res.status(404).json({ message: `Not found` })
|
|
})
|
|
|
|
// Handle any unexpected errors
|
|
app.use((err, req, res, next) => {
|
|
res.status(500).json({ message: `Internal error: ${err.message}` })
|
|
})
|
|
|
|
const server = http.createServer(app)
|
|
return { app, server }
|
|
}
|