aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/client.ts32
-rw-r--r--server/controllers/static.ts14
2 files changed, 17 insertions, 29 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 49e6fd661..bd1f19f8c 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -3,12 +3,11 @@ import { constants, promises as fs } from 'fs'
3import { join } from 'path' 3import { join } from 'path'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' 5import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
6import { HttpStatusCode } from '@shared/core-utils'
6import { root } from '../helpers/core-utils' 7import { root } from '../helpers/core-utils'
7import { logger } from '../helpers/logger' 8import { STATIC_MAX_AGE } from '../initializers/constants'
8import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' 9import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
9import { ClientHtml } from '../lib/client-html'
10import { asyncMiddleware, embedCSP } from '../middlewares' 10import { asyncMiddleware, embedCSP } from '../middlewares'
11import { HttpStatusCode } from '@shared/core-utils'
12 11
13const clientsRouter = express.Router() 12const clientsRouter = express.Router()
14 13
@@ -118,31 +117,12 @@ function serveServerTranslations (req: express.Request, res: express.Response) {
118 return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 117 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
119} 118}
120 119
121async function serveIndexHTML (req: express.Request, res: express.Response) {
122 if (req.accepts(ACCEPT_HEADERS) === 'html') {
123 try {
124 await generateHTMLPage(req, res, req.params.language)
125 return
126 } catch (err) {
127 logger.error('Cannot generate HTML page.', err)
128 }
129 }
130
131 return res.status(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end()
132}
133
134async function generateEmbedHtmlPage (req: express.Request, res: express.Response) { 120async function generateEmbedHtmlPage (req: express.Request, res: express.Response) {
135 const html = await ClientHtml.getEmbedHTML() 121 const html = await ClientHtml.getEmbedHTML()
136 122
137 return sendHTML(html, res) 123 return sendHTML(html, res)
138} 124}
139 125
140async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
141 const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
142
143 return sendHTML(html, res)
144}
145
146async function generateWatchHtmlPage (req: express.Request, res: express.Response) { 126async function generateWatchHtmlPage (req: express.Request, res: express.Response) {
147 const html = await ClientHtml.getWatchHTMLPage(req.params.id + '', req, res) 127 const html = await ClientHtml.getWatchHTMLPage(req.params.id + '', req, res)
148 128
@@ -167,12 +147,6 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express.
167 return sendHTML(html, res) 147 return sendHTML(html, res)
168} 148}
169 149
170function sendHTML (html: string, res: express.Response) {
171 res.set('Content-Type', 'text/html; charset=UTF-8')
172
173 return res.send(html)
174}
175
176async function generateManifest (req: express.Request, res: express.Response) { 150async function generateManifest (req: express.Request, res: express.Response) {
177 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') 151 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest')
178 const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8') 152 const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8')
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index ff77452dd..f12f00e1b 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -27,6 +27,7 @@ import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths'
27import { getThemeOrDefault } from '../lib/plugins/theme-utils' 27import { getThemeOrDefault } from '../lib/plugins/theme-utils'
28import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config' 28import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config'
29import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 29import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
30import { serveIndexHTML } from '@server/lib/client-html'
30 31
31const staticRouter = express.Router() 32const staticRouter = express.Router()
32 33
@@ -119,6 +120,11 @@ staticRouter.get('/robots.txt',
119 } 120 }
120) 121)
121 122
123staticRouter.all('/teapot',
124 getCup,
125 asyncMiddleware(serveIndexHTML)
126)
127
122// security.txt service 128// security.txt service
123staticRouter.get('/security.txt', 129staticRouter.get('/security.txt',
124 (_, res: express.Response) => { 130 (_, res: express.Response) => {
@@ -391,3 +397,11 @@ function getHLSPlaylist (video: MVideoFullLight) {
391 397
392 return Object.assign(playlist, { Video: video }) 398 return Object.assign(playlist, { Video: video })
393} 399}
400
401function getCup (req: express.Request, res: express.Response, next: express.NextFunction) {
402 res.status(HttpStatusCode.I_AM_A_TEAPOT_418)
403 res.setHeader('Accept-Additions', 'Non-Dairy;1,Sugar;1')
404 res.setHeader('Safe', 'if-sepia-awake')
405
406 return next()
407}