diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/client.ts | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index f51470b41..18b8b58e9 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -48,7 +48,26 @@ for (const staticClientFile of staticClientFiles) { | |||
48 | clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) | 48 | clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) |
49 | clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) | 49 | clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) |
50 | 50 | ||
51 | clientsRouter.use('/client/locales/:locale/:file.json', function (req, res) { | 51 | clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations) |
52 | |||
53 | // 404 for static files not found | ||
54 | clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => { | ||
55 | res.sendStatus(404) | ||
56 | }) | ||
57 | |||
58 | // Always serve index client page (the client is a single page application, let it handle routing) | ||
59 | // Try to provide the right language index.html | ||
60 | clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML)) | ||
61 | |||
62 | // --------------------------------------------------------------------------- | ||
63 | |||
64 | export { | ||
65 | clientsRouter | ||
66 | } | ||
67 | |||
68 | // --------------------------------------------------------------------------- | ||
69 | |||
70 | async function serveServerTranslations (req: express.Request, res: express.Response) { | ||
52 | const locale = req.params.locale | 71 | const locale = req.params.locale |
53 | const file = req.params.file | 72 | const file = req.params.file |
54 | 73 | ||
@@ -59,16 +78,9 @@ clientsRouter.use('/client/locales/:locale/:file.json', function (req, res) { | |||
59 | } | 78 | } |
60 | 79 | ||
61 | return res.sendStatus(404) | 80 | return res.sendStatus(404) |
62 | }) | 81 | } |
63 | |||
64 | // 404 for static files not found | ||
65 | clientsRouter.use('/client/*', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
66 | res.sendStatus(404) | ||
67 | }) | ||
68 | 82 | ||
69 | // Always serve index client page (the client is a single page application, let it handle routing) | 83 | async function serveIndexHTML (req: express.Request, res: express.Response) { |
70 | // Try to provide the right language index.html | ||
71 | clientsRouter.use('/(:language)?', async function (req, res) { | ||
72 | if (req.accepts(ACCEPT_HEADERS) === 'html') { | 84 | if (req.accepts(ACCEPT_HEADERS) === 'html') { |
73 | try { | 85 | try { |
74 | await generateHTMLPage(req, res, req.params.language) | 86 | await generateHTMLPage(req, res, req.params.language) |
@@ -79,16 +91,8 @@ clientsRouter.use('/(:language)?', async function (req, res) { | |||
79 | } | 91 | } |
80 | 92 | ||
81 | return res.status(404).end() | 93 | return res.status(404).end() |
82 | }) | ||
83 | |||
84 | // --------------------------------------------------------------------------- | ||
85 | |||
86 | export { | ||
87 | clientsRouter | ||
88 | } | 94 | } |
89 | 95 | ||
90 | // --------------------------------------------------------------------------- | ||
91 | |||
92 | async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { | 96 | async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { |
93 | const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang) | 97 | const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang) |
94 | 98 | ||