mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Convert server and router files to ES modules
GitOrigin-RevId: dab330dd89afb156db6586d8c28b146216548477
This commit is contained in:
parent
e128e8ea32
commit
5a5995f43c
3 changed files with 134 additions and 138 deletions
|
@ -13,7 +13,7 @@ import https from 'node:https'
|
||||||
|
|
||||||
import * as Serializers from './app/src/infrastructure/LoggerSerializers.js'
|
import * as Serializers from './app/src/infrastructure/LoggerSerializers.js'
|
||||||
|
|
||||||
import Server from './app/src/infrastructure/Server.js'
|
import Server from './app/src/infrastructure/Server.mjs'
|
||||||
import QueueWorkers from './app/src/infrastructure/QueueWorkers.js'
|
import QueueWorkers from './app/src/infrastructure/QueueWorkers.js'
|
||||||
import mongodb from './app/src/infrastructure/mongodb.js'
|
import mongodb from './app/src/infrastructure/mongodb.js'
|
||||||
import mongoose from './app/src/infrastructure/Mongoose.js'
|
import mongoose from './app/src/infrastructure/Mongoose.js'
|
||||||
|
|
|
@ -1,49 +1,46 @@
|
||||||
const Path = require('path')
|
import express from 'express'
|
||||||
const express = require('express')
|
import Settings from '@overleaf/settings'
|
||||||
const Settings = require('@overleaf/settings')
|
import logger from '@overleaf/logger'
|
||||||
const logger = require('@overleaf/logger')
|
import metrics from '@overleaf/metrics'
|
||||||
const metrics = require('@overleaf/metrics')
|
import Validation from './Validation.js'
|
||||||
const Validation = require('./Validation')
|
import csp from './CSP.js'
|
||||||
const csp = require('./CSP')
|
import Router from '../router.mjs'
|
||||||
const Router = require('../router')
|
import helmet from 'helmet'
|
||||||
const helmet = require('helmet')
|
import UserSessionsRedis from '../Features/User/UserSessionsRedis.js'
|
||||||
const UserSessionsRedis = require('../Features/User/UserSessionsRedis')
|
import Csrf from './Csrf.js'
|
||||||
const Csrf = require('./Csrf')
|
import HttpPermissionsPolicyMiddleware from './HttpPermissionsPolicy.js'
|
||||||
const HttpPermissionsPolicyMiddleware = require('./HttpPermissionsPolicy')
|
import SessionAutostartMiddleware from './SessionAutostartMiddleware.js'
|
||||||
|
import AnalyticsManager from '../Features/Analytics/AnalyticsManager.js'
|
||||||
|
import session from 'express-session'
|
||||||
|
import CookieMetrics from './CookieMetrics.js'
|
||||||
|
import CustomSessionStore from './CustomSessionStore.js'
|
||||||
|
import bodyParser from './BodyParserWrapper.js'
|
||||||
|
import methodOverride from 'method-override'
|
||||||
|
import cookieParser from 'cookie-parser'
|
||||||
|
import bearerTokenMiddleware from 'express-bearer-token'
|
||||||
|
import passport from 'passport'
|
||||||
|
import { Strategy as LocalStrategy } from 'passport-local'
|
||||||
|
import ReferalConnect from '../Features/Referal/ReferalConnect.js'
|
||||||
|
import RedirectManager from './RedirectManager.js'
|
||||||
|
import translations from './Translations.js'
|
||||||
|
import Views from './Views.js'
|
||||||
|
import Features from './Features.js'
|
||||||
|
import ErrorController from '../Features/Errors/ErrorController.js'
|
||||||
|
import HttpErrorHandler from '../Features/Errors/HttpErrorHandler.js'
|
||||||
|
import UserSessionsManager from '../Features/User/UserSessionsManager.js'
|
||||||
|
import AuthenticationController from '../Features/Authentication/AuthenticationController.js'
|
||||||
|
import SessionManager from '../Features/Authentication/SessionManager.js'
|
||||||
|
import { hasAdminAccess } from '../Features/Helpers/AdminAuthorizationHelper.js'
|
||||||
|
import Modules from './Modules.js'
|
||||||
|
import expressLocals from './ExpressLocals.js'
|
||||||
|
import noCache from 'nocache'
|
||||||
|
import os from 'os'
|
||||||
|
import http from 'http'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
const sessionsRedisClient = UserSessionsRedis.client()
|
const sessionsRedisClient = UserSessionsRedis.client()
|
||||||
|
|
||||||
const SessionAutostartMiddleware = require('./SessionAutostartMiddleware')
|
|
||||||
const AnalyticsManager = require('../Features/Analytics/AnalyticsManager')
|
|
||||||
const session = require('express-session')
|
|
||||||
const CookieMetrics = require('./CookieMetrics')
|
|
||||||
const CustomSessionStore = require('./CustomSessionStore')
|
|
||||||
const bodyParser = require('./BodyParserWrapper')
|
|
||||||
const methodOverride = require('method-override')
|
|
||||||
const cookieParser = require('cookie-parser')
|
|
||||||
const bearerTokenMiddleware = require('express-bearer-token')
|
|
||||||
|
|
||||||
const passport = require('passport')
|
|
||||||
const LocalStrategy = require('passport-local').Strategy
|
|
||||||
|
|
||||||
const oneDayInMilliseconds = 86400000
|
const oneDayInMilliseconds = 86400000
|
||||||
const ReferalConnect = require('../Features/Referal/ReferalConnect')
|
|
||||||
const RedirectManager = require('./RedirectManager')
|
|
||||||
const translations = require('./Translations')
|
|
||||||
const Views = require('./Views')
|
|
||||||
const Features = require('./Features')
|
|
||||||
|
|
||||||
const ErrorController = require('../Features/Errors/ErrorController')
|
|
||||||
const HttpErrorHandler = require('../Features/Errors/HttpErrorHandler')
|
|
||||||
const UserSessionsManager = require('../Features/User/UserSessionsManager')
|
|
||||||
const AuthenticationController = require('../Features/Authentication/AuthenticationController')
|
|
||||||
const SessionManager = require('../Features/Authentication/SessionManager')
|
|
||||||
const {
|
|
||||||
hasAdminAccess,
|
|
||||||
} = require('../Features/Helpers/AdminAuthorizationHelper')
|
|
||||||
|
|
||||||
const Modules = require('./Modules')
|
|
||||||
const expressLocals = require('./ExpressLocals')
|
|
||||||
|
|
||||||
const STATIC_CACHE_AGE = Settings.cacheStaticAssets
|
const STATIC_CACHE_AGE = Settings.cacheStaticAssets
|
||||||
? oneDayInMilliseconds * 365
|
? oneDayInMilliseconds * 365
|
||||||
|
@ -67,7 +64,7 @@ if (Settings.behindProxy) {
|
||||||
* X-Original-Forwarded-For. Express expects all proxy IPs to be in a comma
|
* X-Original-Forwarded-For. Express expects all proxy IPs to be in a comma
|
||||||
* separated list in X-Forwarded-For.
|
* separated list in X-Forwarded-For.
|
||||||
*/
|
*/
|
||||||
app.use(function getForwardedForHeader(req, res, next) {
|
app.use((req, res, next) => {
|
||||||
if (
|
if (
|
||||||
req.headers['x-original-forwarded-for'] &&
|
req.headers['x-original-forwarded-for'] &&
|
||||||
req.headers['x-forwarded-for']
|
req.headers['x-forwarded-for']
|
||||||
|
@ -92,7 +89,7 @@ const ORIGINAL_REQ_IP = Object.getOwnPropertyDescriptor(
|
||||||
Object.defineProperty(app.request, 'ip', {
|
Object.defineProperty(app.request, 'ip', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function ipWithCache() {
|
get() {
|
||||||
const ip = ORIGINAL_REQ_IP.call(this)
|
const ip = ORIGINAL_REQ_IP.call(this)
|
||||||
// Shadow the prototype level getter with a property on the instance.
|
// Shadow the prototype level getter with a property on the instance.
|
||||||
// Any future access on `req.ip` will get served by the instance property.
|
// Any future access on `req.ip` will get served by the instance property.
|
||||||
|
@ -100,7 +97,8 @@ Object.defineProperty(app.request, 'ip', {
|
||||||
return ip
|
return ip
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
app.use(function ignoreAbortedConnections(req, res, next) {
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
if (req.destroyed) {
|
if (req.destroyed) {
|
||||||
// Request has been aborted already.
|
// Request has been aborted already.
|
||||||
return
|
return
|
||||||
|
@ -114,20 +112,21 @@ app.use(function ignoreAbortedConnections(req, res, next) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Settings.exposeHostname) {
|
if (Settings.exposeHostname) {
|
||||||
const HOSTNAME = require('os').hostname()
|
const HOSTNAME = os.hostname()
|
||||||
app.use(function exposeHostname(req, res, next) {
|
app.use((req, res, next) => {
|
||||||
res.setHeader('X-Served-By', HOSTNAME)
|
res.setHeader('X-Served-By', HOSTNAME)
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
webRouter.use(
|
webRouter.use(
|
||||||
express.static(Path.join(__dirname, '/../../../public'), {
|
express.static(fileURLToPath(new URL('../../../public', import.meta.url)), {
|
||||||
maxAge: STATIC_CACHE_AGE,
|
maxAge: STATIC_CACHE_AGE,
|
||||||
setHeaders: csp.removeCSPHeaders,
|
setHeaders: csp.removeCSPHeaders,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
app.set('views', Path.join(__dirname, '/../../views'))
|
|
||||||
|
app.set('views', fileURLToPath(new URL('../../views', import.meta.url)))
|
||||||
app.set('view engine', 'pug')
|
app.set('view engine', 'pug')
|
||||||
|
|
||||||
if (Settings.enabledServices.includes('web')) {
|
if (Settings.enabledServices.includes('web')) {
|
||||||
|
@ -144,7 +143,7 @@ if (Settings.enabledServices.includes('web')) {
|
||||||
|
|
||||||
app.use(metrics.http.monitor(logger))
|
app.use(metrics.http.monitor(logger))
|
||||||
|
|
||||||
Modules.applyMiddleware(app, 'appMiddleware')
|
await Modules.applyMiddleware(app, 'appMiddleware')
|
||||||
app.use(bodyParser.urlencoded({ extended: true, limit: '2mb' }))
|
app.use(bodyParser.urlencoded({ extended: true, limit: '2mb' }))
|
||||||
app.use(bodyParser.json({ limit: Settings.max_json_request_size }))
|
app.use(bodyParser.json({ limit: Settings.max_json_request_size }))
|
||||||
app.use(methodOverride())
|
app.use(methodOverride())
|
||||||
|
@ -160,7 +159,6 @@ if (Settings.useHttpPermissionsPolicy) {
|
||||||
Settings.httpPermissions
|
Settings.httpPermissions
|
||||||
)
|
)
|
||||||
logger.debug('adding permissions policy config', Settings.httpPermissions)
|
logger.debug('adding permissions policy config', Settings.httpPermissions)
|
||||||
|
|
||||||
webRouter.use(httpPermissionsPolicy.middleware)
|
webRouter.use(httpPermissionsPolicy.middleware)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +177,7 @@ const sessionSecrets = [
|
||||||
webRouter.use(cookieParser(sessionSecrets))
|
webRouter.use(cookieParser(sessionSecrets))
|
||||||
webRouter.use(CookieMetrics.middleware)
|
webRouter.use(CookieMetrics.middleware)
|
||||||
SessionAutostartMiddleware.applyInitialMiddleware(webRouter)
|
SessionAutostartMiddleware.applyInitialMiddleware(webRouter)
|
||||||
Modules.applyMiddleware(webRouter, 'sessionMiddleware', {
|
await Modules.applyMiddleware(webRouter, 'sessionMiddleware', {
|
||||||
store: sessionStore,
|
store: sessionStore,
|
||||||
})
|
})
|
||||||
webRouter.use(
|
webRouter.use(
|
||||||
|
@ -199,6 +197,7 @@ webRouter.use(
|
||||||
rolling: Settings.cookieRollingSession === true,
|
rolling: Settings.cookieRollingSession === true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Features.hasFeature('saas')) {
|
if (Features.hasFeature('saas')) {
|
||||||
webRouter.use(AnalyticsManager.analyticsIdMiddleware)
|
webRouter.use(AnalyticsManager.analyticsIdMiddleware)
|
||||||
}
|
}
|
||||||
|
@ -220,13 +219,13 @@ passport.use(
|
||||||
passport.serializeUser(AuthenticationController.serializeUser)
|
passport.serializeUser(AuthenticationController.serializeUser)
|
||||||
passport.deserializeUser(AuthenticationController.deserializeUser)
|
passport.deserializeUser(AuthenticationController.deserializeUser)
|
||||||
|
|
||||||
Modules.hooks.fire('passportSetup', passport, function (err) {
|
Modules.hooks.fire('passportSetup', passport, err => {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
logger.err({ err }, 'error setting up passport in modules')
|
logger.err({ err }, 'error setting up passport in modules')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Modules.applyNonCsrfRouter(webRouter, privateApiRouter, publicApiRouter)
|
await Modules.applyNonCsrfRouter(webRouter, privateApiRouter, publicApiRouter)
|
||||||
|
|
||||||
webRouter.csrf = new Csrf()
|
webRouter.csrf = new Csrf()
|
||||||
webRouter.use(webRouter.csrf.middleware)
|
webRouter.use(webRouter.csrf.middleware)
|
||||||
|
@ -235,7 +234,7 @@ webRouter.use(translations.setLangBasedOnDomainMiddleware)
|
||||||
|
|
||||||
if (Settings.cookieRollingSession) {
|
if (Settings.cookieRollingSession) {
|
||||||
// Measure expiry from last request, not last login
|
// Measure expiry from last request, not last login
|
||||||
webRouter.use(function touchSession(req, res, next) {
|
webRouter.use((req, res, next) => {
|
||||||
if (!req.session.noSessionCallback) {
|
if (!req.session.noSessionCallback) {
|
||||||
req.session.touch()
|
req.session.touch()
|
||||||
if (SessionManager.isUserLoggedIn(req.session)) {
|
if (SessionManager.isUserLoggedIn(req.session)) {
|
||||||
|
@ -255,7 +254,6 @@ if (Settings.cookieRollingSession) {
|
||||||
|
|
||||||
webRouter.use(ReferalConnect.use)
|
webRouter.use(ReferalConnect.use)
|
||||||
expressLocals(webRouter, privateApiRouter, publicApiRouter)
|
expressLocals(webRouter, privateApiRouter, publicApiRouter)
|
||||||
|
|
||||||
webRouter.use(SessionAutostartMiddleware.invokeCallbackMiddleware)
|
webRouter.use(SessionAutostartMiddleware.invokeCallbackMiddleware)
|
||||||
|
|
||||||
webRouter.use(function checkIfSiteClosed(req, res, next) {
|
webRouter.use(function checkIfSiteClosed(req, res, next) {
|
||||||
|
@ -281,8 +279,8 @@ webRouter.use(function checkIfEditorClosed(req, res, next) {
|
||||||
webRouter.use(AuthenticationController.validateAdmin)
|
webRouter.use(AuthenticationController.validateAdmin)
|
||||||
|
|
||||||
// add security headers using Helmet
|
// add security headers using Helmet
|
||||||
const noCacheMiddleware = require('nocache')()
|
const noCacheMiddleware = noCache()
|
||||||
webRouter.use(function addNoCacheHeader(req, res, next) {
|
webRouter.use((req, res, next) => {
|
||||||
const isProjectPage = /^\/project\/[a-f0-9]{24}$/.test(req.path)
|
const isProjectPage = /^\/project\/[a-f0-9]{24}$/.test(req.path)
|
||||||
if (isProjectPage) {
|
if (isProjectPage) {
|
||||||
// always set no-cache headers on a project page, as it could be an anonymous token viewer
|
// always set no-cache headers on a project page, as it could be an anonymous token viewer
|
||||||
|
@ -319,6 +317,7 @@ webRouter.use(function addNoCacheHeader(req, res, next) {
|
||||||
// allow other responses (anonymous users, except for project pages) to be cached
|
// allow other responses (anonymous users, except for project pages) to be cached
|
||||||
return next()
|
return next()
|
||||||
})
|
})
|
||||||
|
|
||||||
webRouter.use(
|
webRouter.use(
|
||||||
helmet({
|
helmet({
|
||||||
// note that more headers are added by default
|
// note that more headers are added by default
|
||||||
|
@ -346,22 +345,21 @@ if (Settings.csp && Settings.csp.enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('creating HTTP server'.yellow)
|
logger.debug('creating HTTP server'.yellow)
|
||||||
const server = require('http').createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
||||||
// provide settings for separate web and api processes
|
// provide settings for separate web and api processes
|
||||||
if (Settings.enabledServices.includes('api')) {
|
if (Settings.enabledServices.includes('api')) {
|
||||||
logger.debug('providing api router')
|
logger.debug({}, 'providing api router')
|
||||||
app.use(privateApiRouter)
|
app.use(privateApiRouter)
|
||||||
app.use(Validation.errorMiddleware)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleApiError)
|
app.use(ErrorController.handleApiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.enabledServices.includes('web')) {
|
if (Settings.enabledServices.includes('web')) {
|
||||||
logger.debug('providing web router')
|
logger.debug({}, 'providing web router')
|
||||||
app.use(publicApiRouter) // public API goes with web router for public access
|
app.use(publicApiRouter) // public API goes with web router for public access
|
||||||
app.use(Validation.errorMiddleware)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleApiError)
|
app.use(ErrorController.handleApiError)
|
||||||
|
|
||||||
app.use(webRouter)
|
app.use(webRouter)
|
||||||
app.use(Validation.errorMiddleware)
|
app.use(Validation.errorMiddleware)
|
||||||
app.use(ErrorController.handleError)
|
app.use(ErrorController.handleError)
|
||||||
|
@ -370,9 +368,6 @@ if (Settings.enabledServices.includes('web')) {
|
||||||
metrics.injectMetricsRoute(webRouter)
|
metrics.injectMetricsRoute(webRouter)
|
||||||
metrics.injectMetricsRoute(privateApiRouter)
|
metrics.injectMetricsRoute(privateApiRouter)
|
||||||
|
|
||||||
Router.initialize(webRouter, privateApiRouter, publicApiRouter)
|
await Router.initialize(webRouter, privateApiRouter, publicApiRouter)
|
||||||
|
|
||||||
module.exports = {
|
export default { app, server }
|
||||||
app,
|
|
||||||
server,
|
|
||||||
}
|
|
|
@ -1,76 +1,77 @@
|
||||||
const AdminController = require('./Features/ServerAdmin/AdminController')
|
import AdminController from './Features/ServerAdmin/AdminController.js'
|
||||||
const ErrorController = require('./Features/Errors/ErrorController')
|
import ErrorController from './Features/Errors/ErrorController.js'
|
||||||
const ProjectController = require('./Features/Project/ProjectController')
|
import Features from './infrastructure/Features.js'
|
||||||
const ProjectApiController = require('./Features/Project/ProjectApiController')
|
import ProjectController from './Features/Project/ProjectController.js'
|
||||||
const ProjectListController = require('./Features/Project/ProjectListController')
|
import ProjectApiController from './Features/Project/ProjectApiController.js'
|
||||||
const SpellingController = require('./Features/Spelling/SpellingController')
|
import ProjectListController from './Features/Project/ProjectListController.js'
|
||||||
const EditorRouter = require('./Features/Editor/EditorRouter')
|
import SpellingController from './Features/Spelling/SpellingController.js'
|
||||||
const Settings = require('@overleaf/settings')
|
import EditorRouter from './Features/Editor/EditorRouter.js'
|
||||||
const TpdsController = require('./Features/ThirdPartyDataStore/TpdsController')
|
import Settings from '@overleaf/settings'
|
||||||
const SubscriptionRouter = require('./Features/Subscription/SubscriptionRouter')
|
import TpdsController from './Features/ThirdPartyDataStore/TpdsController.js'
|
||||||
const UploadsRouter = require('./Features/Uploads/UploadsRouter')
|
import SubscriptionRouter from './Features/Subscription/SubscriptionRouter.js'
|
||||||
const metrics = require('@overleaf/metrics')
|
import UploadsRouter from './Features/Uploads/UploadsRouter.js'
|
||||||
const ReferalController = require('./Features/Referal/ReferalController')
|
import metrics from '@overleaf/metrics'
|
||||||
const AuthenticationController = require('./Features/Authentication/AuthenticationController')
|
import ReferalController from './Features/Referal/ReferalController.js'
|
||||||
const PermissionsController = require('./Features/Authorization/PermissionsController')
|
import AuthenticationController from './Features/Authentication/AuthenticationController.js'
|
||||||
const SessionManager = require('./Features/Authentication/SessionManager')
|
import PermissionsController from './Features/Authorization/PermissionsController.js'
|
||||||
const TagsController = require('./Features/Tags/TagsController')
|
import SessionManager from './Features/Authentication/SessionManager.js'
|
||||||
const NotificationsController = require('./Features/Notifications/NotificationsController')
|
import TagsController from './Features/Tags/TagsController.js'
|
||||||
const CollaboratorsRouter = require('./Features/Collaborators/CollaboratorsRouter')
|
import NotificationsController from './Features/Notifications/NotificationsController.js'
|
||||||
const UserInfoController = require('./Features/User/UserInfoController')
|
import CollaboratorsRouter from './Features/Collaborators/CollaboratorsRouter.js'
|
||||||
const UserController = require('./Features/User/UserController')
|
import UserInfoController from './Features/User/UserInfoController.js'
|
||||||
const UserEmailsController = require('./Features/User/UserEmailsController')
|
import UserController from './Features/User/UserController.js'
|
||||||
const UserPagesController = require('./Features/User/UserPagesController')
|
import UserEmailsController from './Features/User/UserEmailsController.js'
|
||||||
const TutorialController = require('./Features/Tutorial/TutorialController')
|
import UserPagesController from './Features/User/UserPagesController.js'
|
||||||
const DocumentController = require('./Features/Documents/DocumentController')
|
import TutorialController from './Features/Tutorial/TutorialController.js'
|
||||||
const CompileManager = require('./Features/Compile/CompileManager')
|
import DocumentController from './Features/Documents/DocumentController.js'
|
||||||
const CompileController = require('./Features/Compile/CompileController')
|
import CompileManager from './Features/Compile/CompileManager.js'
|
||||||
const ClsiCookieManager = require('./Features/Compile/ClsiCookieManager')(
|
import CompileController from './Features/Compile/CompileController.js'
|
||||||
Settings.apis.clsi != null ? Settings.apis.clsi.backendGroupName : undefined
|
import ClsiCookieManagerFactory from './Features/Compile/ClsiCookieManager.js'
|
||||||
)
|
import HealthCheckController from './Features/HealthCheck/HealthCheckController.js'
|
||||||
const HealthCheckController = require('./Features/HealthCheck/HealthCheckController')
|
import ProjectDownloadsController from './Features/Downloads/ProjectDownloadsController.js'
|
||||||
const ProjectDownloadsController = require('./Features/Downloads/ProjectDownloadsController')
|
import FileStoreController from './Features/FileStore/FileStoreController.js'
|
||||||
const FileStoreController = require('./Features/FileStore/FileStoreController')
|
import DocumentUpdaterController from './Features/DocumentUpdater/DocumentUpdaterController.js'
|
||||||
const DocumentUpdaterController = require('./Features/DocumentUpdater/DocumentUpdaterController')
|
import HistoryController from './Features/History/HistoryController.js'
|
||||||
const HistoryController = require('./Features/History/HistoryController')
|
import ExportsController from './Features/Exports/ExportsController.js'
|
||||||
const ExportsController = require('./Features/Exports/ExportsController')
|
import PasswordResetRouter from './Features/PasswordReset/PasswordResetRouter.js'
|
||||||
const PasswordResetRouter = require('./Features/PasswordReset/PasswordResetRouter')
|
import StaticPagesRouter from './Features/StaticPages/StaticPagesRouter.js'
|
||||||
const StaticPagesRouter = require('./Features/StaticPages/StaticPagesRouter')
|
import ChatController from './Features/Chat/ChatController.js'
|
||||||
const ChatController = require('./Features/Chat/ChatController')
|
import Modules from './infrastructure/Modules.js'
|
||||||
const Modules = require('./infrastructure/Modules')
|
import {
|
||||||
const {
|
|
||||||
RateLimiter,
|
RateLimiter,
|
||||||
openProjectRateLimiter,
|
openProjectRateLimiter,
|
||||||
overleafLoginRateLimiter,
|
overleafLoginRateLimiter,
|
||||||
} = require('./infrastructure/RateLimiter')
|
} from './infrastructure/RateLimiter.js'
|
||||||
const RateLimiterMiddleware = require('./Features/Security/RateLimiterMiddleware')
|
import RateLimiterMiddleware from './Features/Security/RateLimiterMiddleware.js'
|
||||||
const InactiveProjectController = require('./Features/InactiveData/InactiveProjectController')
|
import InactiveProjectController from './Features/InactiveData/InactiveProjectController.js'
|
||||||
const ContactRouter = require('./Features/Contacts/ContactRouter')
|
import ContactRouter from './Features/Contacts/ContactRouter.js'
|
||||||
const ReferencesController = require('./Features/References/ReferencesController')
|
import ReferencesController from './Features/References/ReferencesController.js'
|
||||||
const AuthorizationMiddleware = require('./Features/Authorization/AuthorizationMiddleware')
|
import AuthorizationMiddleware from './Features/Authorization/AuthorizationMiddleware.js'
|
||||||
const BetaProgramController = require('./Features/BetaProgram/BetaProgramController')
|
import BetaProgramController from './Features/BetaProgram/BetaProgramController.js'
|
||||||
const AnalyticsRouter = require('./Features/Analytics/AnalyticsRouter')
|
import AnalyticsRouter from './Features/Analytics/AnalyticsRouter.js'
|
||||||
const MetaController = require('./Features/Metadata/MetaController')
|
import MetaController from './Features/Metadata/MetaController.js'
|
||||||
const TokenAccessController = require('./Features/TokenAccess/TokenAccessController')
|
import TokenAccessController from './Features/TokenAccess/TokenAccessController.js'
|
||||||
const TokenAccessRouter = require('./Features/TokenAccess/TokenAccessRouter')
|
import TokenAccessRouter from './Features/TokenAccess/TokenAccessRouter.js'
|
||||||
const Features = require('./infrastructure/Features')
|
import LinkedFilesRouter from './Features/LinkedFiles/LinkedFilesRouter.js'
|
||||||
const LinkedFilesRouter = require('./Features/LinkedFiles/LinkedFilesRouter')
|
import TemplatesRouter from './Features/Templates/TemplatesRouter.js'
|
||||||
const TemplatesRouter = require('./Features/Templates/TemplatesRouter')
|
import UserMembershipRouter from './Features/UserMembership/UserMembershipRouter.js'
|
||||||
const UserMembershipRouter = require('./Features/UserMembership/UserMembershipRouter')
|
import SystemMessageController from './Features/SystemMessages/SystemMessageController.js'
|
||||||
const SystemMessageController = require('./Features/SystemMessages/SystemMessageController')
|
import AnalyticsRegistrationSourceMiddleware from './Features/Analytics/AnalyticsRegistrationSourceMiddleware.js'
|
||||||
const AnalyticsRegistrationSourceMiddleware = require('./Features/Analytics/AnalyticsRegistrationSourceMiddleware')
|
import AnalyticsUTMTrackingMiddleware from './Features/Analytics/AnalyticsUTMTrackingMiddleware.js'
|
||||||
const AnalyticsUTMTrackingMiddleware = require('./Features/Analytics/AnalyticsUTMTrackingMiddleware')
|
import CaptchaMiddleware from './Features/Captcha/CaptchaMiddleware.js'
|
||||||
const CaptchaMiddleware = require('./Features/Captcha/CaptchaMiddleware')
|
import { Joi, validate } from './infrastructure/Validation.js'
|
||||||
const { Joi, validate } = require('./infrastructure/Validation')
|
import {
|
||||||
const {
|
|
||||||
renderUnsupportedBrowserPage,
|
renderUnsupportedBrowserPage,
|
||||||
unsupportedBrowserMiddleware,
|
unsupportedBrowserMiddleware,
|
||||||
} = require('./infrastructure/UnsupportedBrowserMiddleware')
|
} from './infrastructure/UnsupportedBrowserMiddleware.js'
|
||||||
|
|
||||||
const logger = require('@overleaf/logger')
|
import logger from '@overleaf/logger'
|
||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const { plainTextResponse } = require('./infrastructure/Response')
|
import { plainTextResponse } from './infrastructure/Response.js'
|
||||||
const PublicAccessLevels = require('./Features/Authorization/PublicAccessLevels')
|
import PublicAccessLevels from './Features/Authorization/PublicAccessLevels.js'
|
||||||
|
const ClsiCookieManager = ClsiCookieManagerFactory(
|
||||||
|
Settings.apis.clsi != null ? Settings.apis.clsi.backendGroupName : undefined
|
||||||
|
)
|
||||||
|
|
||||||
const rateLimiters = {
|
const rateLimiters = {
|
||||||
addEmail: new RateLimiter('add-email', {
|
addEmail: new RateLimiter('add-email', {
|
||||||
|
@ -212,7 +213,7 @@ const rateLimiters = {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
async function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
webRouter.use(unsupportedBrowserMiddleware)
|
webRouter.use(unsupportedBrowserMiddleware)
|
||||||
|
|
||||||
if (!Settings.allowPublicAccess) {
|
if (!Settings.allowPublicAccess) {
|
||||||
|
@ -291,7 +292,7 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
UserMembershipRouter.apply(webRouter)
|
UserMembershipRouter.apply(webRouter)
|
||||||
TokenAccessRouter.apply(webRouter)
|
TokenAccessRouter.apply(webRouter)
|
||||||
|
|
||||||
Modules.applyRouter(webRouter, privateApiRouter, publicApiRouter)
|
await Modules.applyRouter(webRouter, privateApiRouter, publicApiRouter)
|
||||||
|
|
||||||
if (Settings.enableSubscriptions) {
|
if (Settings.enableSubscriptions) {
|
||||||
webRouter.get(
|
webRouter.get(
|
||||||
|
@ -1377,4 +1378,4 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
webRouter.get('*', ErrorController.notFound)
|
webRouter.get('*', ErrorController.notFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { initialize, rateLimiters }
|
export default { initialize, rateLimiters }
|
Loading…
Reference in a new issue