diff options
Diffstat (limited to 'server/controllers/themes.ts')
-rw-r--r-- | server/controllers/themes.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/server/controllers/themes.ts b/server/controllers/themes.ts new file mode 100644 index 000000000..20e7062d0 --- /dev/null +++ b/server/controllers/themes.ts | |||
@@ -0,0 +1,28 @@ | |||
1 | import * as express from 'express' | ||
2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | ||
3 | import { join } from 'path' | ||
4 | import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | ||
5 | import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' | ||
6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' | ||
7 | |||
8 | const themesRouter = express.Router() | ||
9 | |||
10 | themesRouter.get('/:themeName/:themeVersion/css/:staticEndpoint', | ||
11 | serveThemeCSSValidator, | ||
12 | serveThemeCSSDirectory | ||
13 | ) | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | themesRouter | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | ||
24 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | ||
25 | const staticEndpoint = req.params.staticEndpoint | ||
26 | |||
27 | return express.static(join(plugin.path, staticEndpoint), { fallthrough: false }) | ||
28 | } | ||