mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #28541 from overleaf/td-notifications-app-ts
Change notifications app.js to TypeScript GitOrigin-RevId: cb6195e2e8c8cd89e1a954bfcb1911929440d6ca
This commit is contained in:
@@ -24,4 +24,5 @@ COPY services/notifications/ /overleaf/services/notifications/
|
||||
FROM app
|
||||
USER node
|
||||
|
||||
CMD ["node", "--expose-gc", "app.js"]
|
||||
CMD ["node", "--expose-gc", "app.ts"]
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@ import '@overleaf/metrics/initialize.js'
|
||||
import metrics from '@overleaf/metrics'
|
||||
import Settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger'
|
||||
import express from 'express'
|
||||
import express, {
|
||||
type Request,
|
||||
type Response,
|
||||
type ErrorRequestHandler,
|
||||
type NextFunction,
|
||||
} from 'express'
|
||||
import methodOverride from 'method-override'
|
||||
import { mongoClient } from './app/js/mongodb.js'
|
||||
import NotificationsController from './app/js/NotificationsController.ts'
|
||||
@@ -44,9 +49,12 @@ app.get('/health_check', HealthCheckController.check)
|
||||
|
||||
app.get('*', (req, res) => res.sendStatus(404))
|
||||
|
||||
app.use(handleApiError)
|
||||
|
||||
function handleApiError(err, req, res, next) {
|
||||
const handleApiError: ErrorRequestHandler = (
|
||||
err: Error,
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
req.logger.addFields({ err })
|
||||
if (err instanceof ParamsError) {
|
||||
req.logger.setLevel('warn')
|
||||
@@ -60,6 +68,8 @@ function handleApiError(err, req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
app.use(handleApiError)
|
||||
|
||||
const host = Settings.internal.notifications?.host || '127.0.0.1'
|
||||
const port = Settings.internal.notifications?.port || 3042
|
||||
try {
|
||||
@@ -8,4 +8,5 @@ notifications
|
||||
--public-repo=True
|
||||
--test-acceptance-vitest=True
|
||||
--test-unit-vitest=True
|
||||
--ts-app=True
|
||||
--tsconfig-extra-includes=vitest.config.unit.cjs,vitest.config.acceptance.cjs
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
"name": "@overleaf/notifications",
|
||||
"description": "An API to handle user notifications",
|
||||
"private": true,
|
||||
"main": "app.js",
|
||||
"main": "app.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"start": "node app.ts",
|
||||
"test:acceptance:_run": "vitest --config ./vitest.config.acceptance.cjs",
|
||||
"test:acceptance": "npm run test:acceptance:_run",
|
||||
"test:unit:_run": "vitest --config ./vitest.config.unit.cjs",
|
||||
@@ -15,7 +15,7 @@
|
||||
"format:fix": "prettier --write $PWD/'**/{*.*js,*.ts}'",
|
||||
"lint:fix": "eslint --fix .",
|
||||
"types:check": "tsc --noEmit",
|
||||
"nodemon": "node --watch app.js"
|
||||
"nodemon": "node --watch app.ts"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -38,6 +38,7 @@
|
||||
"zod-validation-error": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/method-override": "^3.0.0",
|
||||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"mocha": "^11.1.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { beforeAll, describe, it, expect } from 'vitest'
|
||||
import { fetchStringWithResponse } from '@overleaf/fetch-utils'
|
||||
import app from '../../../app.js'
|
||||
import app from '../../../app.ts'
|
||||
import logger from '@overleaf/logger'
|
||||
|
||||
let runAppPromise: Promise<void> | null = null
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"extends": "../../tsconfig.backend.json",
|
||||
"include": [
|
||||
"app.js",
|
||||
"app.ts",
|
||||
"app/js/**/*",
|
||||
"benchmarks/**/*",
|
||||
"config/**/*",
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import 'express'
|
||||
import RequestLogger from '@overleaf/metrics'
|
||||
|
||||
// Add properties to Express's Request object that are defined in JS middleware
|
||||
// or controllers and expected to be present in controllers.
|
||||
declare global {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
namespace Express {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
interface Request {
|
||||
logger: RequestLogger
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user