Merge pull request #28541 from overleaf/td-notifications-app-ts

Change notifications app.js to TypeScript

GitOrigin-RevId: cb6195e2e8c8cd89e1a954bfcb1911929440d6ca
This commit is contained in:
Tim Down
2025-10-10 10:04:50 +01:00
committed by Copybot
parent d54efe78f7
commit 7aa66b260c
20 changed files with 61 additions and 13 deletions

View File

@@ -80,14 +80,14 @@ services:
- ../services/history-v1/migrations:/overleaf/services/history-v1/migrations
notifications:
command: ["node", "--watch", "app.js"]
command: ["node", "--watch", "app.ts"]
environment:
- NODE_OPTIONS=--inspect=0.0.0.0:9229
ports:
- "127.0.0.1:9236:9229"
volumes:
- ../services/notifications/app:/overleaf/services/notifications/app
- ../services/notifications/app.js:/overleaf/services/notifications/app.js
- ../services/notifications/app.ts:/overleaf/services/notifications/app.ts
- ../services/notifications/config:/overleaf/services/notifications/config
project-history:

View File

@@ -75,4 +75,4 @@ class RequestLogger {
}
}
module.exports.monitor = monitor
module.exports = { monitor, RequestLogger }

11
package-lock.json generated
View File

@@ -19307,6 +19307,16 @@
"@types/node": "*"
}
},
"node_modules/@types/method-override": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/method-override/-/method-override-3.0.0.tgz",
"integrity": "sha512-7XFHR6j7JljprBpzzRZatakUXm1kEGAM3PL/GSsGRHtDvOAKYCdmnXX/5YSl1eQrpJymGs9tRekSWEGaG+Ntjw==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"@types/express": "*"
}
},
"node_modules/@types/mime": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz",
@@ -52114,6 +52124,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",

View File

@@ -9,4 +9,4 @@ fi
source /etc/overleaf/env.sh
export LISTEN_ADDRESS=127.0.0.1
exec /sbin/setuser www-data /usr/bin/node $NODE_PARAMS /overleaf/services/notifications/app.js >> /var/log/overleaf/notifications.log 2>&1
exec /sbin/setuser www-data /usr/bin/node $NODE_PARAMS /overleaf/services/notifications/app.ts >> /var/log/overleaf/notifications.log 2>&1

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -3,6 +3,7 @@
"include": [
"api/**/*",
"app.js",
"app.ts",
"app/js/**/*",
"backup-deletion-app.mjs",
"backup-verifier-app.mjs",

View File

@@ -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"]

View File

@@ -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 {

View File

@@ -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

View File

@@ -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",

View File

@@ -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

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -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
}
}
}

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",

View File

@@ -2,6 +2,7 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app.ts",
"app/js/**/*",
"benchmarks/**/*",
"config/**/*",