2019-07-05 06:54:32 -05:00
|
|
|
import * as express from 'express'
|
|
|
|
import { join } from 'path'
|
|
|
|
import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
|
|
|
|
import { serveThemeCSSValidator } from '../middlewares/validators/themes'
|
|
|
|
|
|
|
|
const themesRouter = express.Router()
|
|
|
|
|
2019-07-10 07:06:19 -05:00
|
|
|
themesRouter.get('/:themeName/:themeVersion/css/:staticEndpoint(*)',
|
2019-07-05 06:54:32 -05:00
|
|
|
serveThemeCSSValidator,
|
|
|
|
serveThemeCSSDirectory
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
themesRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
|
|
|
|
const plugin: RegisteredPlugin = res.locals.registeredPlugin
|
|
|
|
const staticEndpoint = req.params.staticEndpoint
|
|
|
|
|
2019-07-10 07:06:19 -05:00
|
|
|
if (plugin.css.includes(staticEndpoint) === false) {
|
|
|
|
return res.sendStatus(404)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.sendFile(join(plugin.path, staticEndpoint))
|
2019-07-05 06:54:32 -05:00
|
|
|
}
|