aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/client.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-25 16:56:41 +0200
committerChocobozzz <me@florianbigard.com>2019-07-25 16:56:41 +0200
commit552d95b1e69fbbd99f5bc300a127457e1b97b9df (patch)
tree1579d43f5265916df94fabb5b516b7640b4289aa /server/controllers/client.ts
parentc8861d5dc0436ef4342ce517241e3591fa256a13 (diff)
downloadPeerTube-552d95b1e69fbbd99f5bc300a127457e1b97b9df.tar.gz
PeerTube-552d95b1e69fbbd99f5bc300a127457e1b97b9df.tar.zst
PeerTube-552d95b1e69fbbd99f5bc300a127457e1b97b9df.zip
Move controller in dedicated functions
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r--server/controllers/client.ts40
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) {
48clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) 48clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
49clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) 49clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE }))
50 50
51clientsRouter.use('/client/locales/:locale/:file.json', function (req, res) { 51clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations)
52
53// 404 for static files not found
54clientsRouter.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
60clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML))
61
62// ---------------------------------------------------------------------------
63
64export {
65 clientsRouter
66}
67
68// ---------------------------------------------------------------------------
69
70async 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
65clientsRouter.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) 83async function serveIndexHTML (req: express.Request, res: express.Response) {
70// Try to provide the right language index.html
71clientsRouter.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
86export {
87 clientsRouter
88} 94}
89 95
90// ---------------------------------------------------------------------------
91
92async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { 96async 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