mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
Merge pull request #19562 from overleaf/ab-modules-dependencies
[web] Modules dependencies GitOrigin-RevId: d8bbb25a754f2ed58b1b1e924aa760b87d3135c6
This commit is contained in:
parent
dcf6e502b9
commit
5bc5b1af2a
7 changed files with 101 additions and 8 deletions
|
@ -41,6 +41,15 @@ function loadModules() {
|
|||
`${moduleName}: module.viewIncludes moved into Settings.viewIncludes`
|
||||
)
|
||||
}
|
||||
if (loadedModule.dependencies) {
|
||||
for (const dependency of loadedModule.dependencies) {
|
||||
if (!Settings.moduleImportSequence.includes(dependency)) {
|
||||
throw new Error(
|
||||
`Module '${dependency}' listed as a dependency of '${moduleName}' is missing in the moduleImportSequence. Please also verify that it is available in the current environment.`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_modulesLoaded = true
|
||||
attachHooks()
|
||||
|
@ -74,7 +83,7 @@ function loadViewIncludes(app) {
|
|||
_viewIncludes = Views.compileViewIncludes(app)
|
||||
}
|
||||
|
||||
function registerMiddleware(appOrRouter, middlewareName, options) {
|
||||
function applyMiddleware(appOrRouter, middlewareName, options) {
|
||||
if (!middlewareName) {
|
||||
throw new Error(
|
||||
'middleware name must be provided to register module middleware'
|
||||
|
@ -173,7 +182,7 @@ module.exports = {
|
|||
loadViewIncludes,
|
||||
moduleIncludes,
|
||||
moduleIncludesAvailable,
|
||||
registerMiddleware,
|
||||
applyMiddleware,
|
||||
hooks: {
|
||||
attach: attachHook,
|
||||
fire: fireHook,
|
||||
|
|
|
@ -144,7 +144,7 @@ if (Settings.enabledServices.includes('web')) {
|
|||
|
||||
app.use(metrics.http.monitor(logger))
|
||||
|
||||
Modules.registerMiddleware(app, 'appMiddleware')
|
||||
Modules.applyMiddleware(app, 'appMiddleware')
|
||||
app.use(bodyParser.urlencoded({ extended: true, limit: '2mb' }))
|
||||
app.use(bodyParser.json({ limit: Settings.max_json_request_size }))
|
||||
app.use(methodOverride())
|
||||
|
@ -179,7 +179,7 @@ const sessionSecrets = [
|
|||
webRouter.use(cookieParser(sessionSecrets))
|
||||
webRouter.use(CookieMetrics.middleware)
|
||||
SessionAutostartMiddleware.applyInitialMiddleware(webRouter)
|
||||
Modules.registerMiddleware(webRouter, 'sessionMiddleware', {
|
||||
Modules.applyMiddleware(webRouter, 'sessionMiddleware', {
|
||||
store: sessionStore,
|
||||
})
|
||||
webRouter.use(
|
||||
|
|
|
@ -1 +1,6 @@
|
|||
module.exports = {}
|
||||
/** @typedef {import("../../types/web-module").WebModule} WebModule */
|
||||
|
||||
/** @type {WebModule} */
|
||||
const HistoryModule = {}
|
||||
|
||||
module.exports = HistoryModule
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
const LaunchpadRouter = require('./app/src/LaunchpadRouter')
|
||||
|
||||
module.exports = { router: LaunchpadRouter }
|
||||
/** @typedef {import("../../types/web-module").WebModule} WebModule */
|
||||
|
||||
/** @type {WebModule} */
|
||||
const LaunchpadModule = {
|
||||
router: LaunchpadRouter,
|
||||
}
|
||||
|
||||
module.exports = LaunchpadModule
|
||||
|
|
|
@ -1 +1,6 @@
|
|||
module.exports = {}
|
||||
/** @typedef {import("../../types/web-module").WebModule} WebModule */
|
||||
|
||||
/** @type {WebModule} */
|
||||
const ServerCeScriptsModule = {}
|
||||
|
||||
module.exports = ServerCeScriptsModule
|
||||
|
|
|
@ -1,2 +1,10 @@
|
|||
const UserActivateRouter = require('./app/src/UserActivateRouter')
|
||||
module.exports = { router: UserActivateRouter }
|
||||
|
||||
/** @typedef {import("../../types/web-module").WebModule} WebModule */
|
||||
|
||||
/** @type {WebModule} */
|
||||
const UserActivateModule = {
|
||||
router: UserActivateRouter,
|
||||
}
|
||||
|
||||
module.exports = UserActivateModule
|
||||
|
|
59
services/web/types/web-module.ts
Normal file
59
services/web/types/web-module.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
type LinkedFileAgent = {
|
||||
createLinkedFile: (
|
||||
projectId: string,
|
||||
linkedFileData: object,
|
||||
name: string,
|
||||
parentFolderId: string,
|
||||
userId: string,
|
||||
callback: () => void
|
||||
) => void
|
||||
refreshLinkedFile: (
|
||||
projectId: string,
|
||||
linkedFileData: object,
|
||||
name: string,
|
||||
parentFolderId: string,
|
||||
userId: string,
|
||||
callback: () => void
|
||||
) => void
|
||||
promises: {
|
||||
createLinkedFile: (
|
||||
projectId: string,
|
||||
linkedFileData: object,
|
||||
name: string,
|
||||
parentFolderId: string,
|
||||
userId: string
|
||||
) => Promise<any>
|
||||
refreshLinkedFile: (
|
||||
projectId: string,
|
||||
linkedFileData: object,
|
||||
name: string,
|
||||
parentFolderId: string,
|
||||
userId: string
|
||||
) => Promise<any>
|
||||
}
|
||||
}
|
||||
|
||||
export type WebModule = {
|
||||
dependencies?: string[]
|
||||
router?: {
|
||||
apply?: (
|
||||
webRouter: any,
|
||||
privateApiRouter?: any,
|
||||
publicApiRouter?: any
|
||||
) => void
|
||||
}
|
||||
nonCsrfRouter?: {
|
||||
apply: (webRouter: any, privateApiRouter: any, publicApiRouter: any) => void
|
||||
}
|
||||
hooks?: {
|
||||
[name: string]: (args: any[]) => void
|
||||
}
|
||||
middleware?: {
|
||||
[name: string]: (req: any, res: any, next: any) => void
|
||||
}
|
||||
sessionMiddleware?: (webRouter: any, options: any) => void
|
||||
appMiddleware?: (app: any) => void
|
||||
linkedFileAgents?: {
|
||||
[name: string]: () => LinkedFileAgent
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue