X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=0d94cac9b0beec4366ac7d27d99d1f7fdda6177a;hb=0bc53e20296de68288481e2375b297626087174b;hp=5900eaff33f5d48559040cd6d744b801b337ee44;hpb=a24bd1ed41b43790bab6ba789580bb4e85f07d85;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 5900eaff3..0d94cac9b 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -1,5 +1,5 @@ -import * as cors from 'cors' -import * as express from 'express' +import cors from 'cors' +import express from 'express' import { join } from 'path' import { serveIndexHTML } from '@server/lib/client-html' import { ServerConfigManager } from '@server/lib/server-config-manager' @@ -19,7 +19,7 @@ import { } from '../initializers/constants' import { getThemeOrDefault } from '../lib/plugins/theme-utils' import { asyncMiddleware } from '../middlewares' -import { cacheRoute } from '../middlewares/cache' +import { cacheRoute } from '../middlewares/cache/cache' import { UserModel } from '../models/user/user' import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' @@ -32,14 +32,6 @@ staticRouter.use(cors()) Cors is very important to let other servers access torrent and video files */ -// FIXME: deprecated in 3.2, use lazy-statics instead -// Due to historical reasons, we can't really remove this controller -const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR -staticRouter.use( - STATIC_PATHS.TORRENTS, - express.static(torrentsPhysicalPath, { maxAge: 0 }) // Don't cache because we could regenerate the torrent file -) - // Videos path for webseed staticRouter.use( STATIC_PATHS.WEBSEED, @@ -66,9 +58,10 @@ staticRouter.use( // robots.txt service staticRouter.get('/robots.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ROBOTS)), + cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS), (_, res: express.Response) => { res.type('text/plain') + return res.send(CONFIG.INSTANCE.ROBOTS) } ) @@ -86,7 +79,7 @@ staticRouter.get('/security.txt', ) staticRouter.get('/.well-known/security.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SECURITYTXT)), + cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), (_, res: express.Response) => { res.type('text/plain') return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) @@ -95,7 +88,7 @@ staticRouter.get('/.well-known/security.txt', // nodeinfo service staticRouter.use('/.well-known/nodeinfo', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), + cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), (_, res: express.Response) => { return res.json({ links: [ @@ -108,13 +101,13 @@ staticRouter.use('/.well-known/nodeinfo', } ) staticRouter.use('/nodeinfo/:version.json', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), + cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), asyncMiddleware(generateNodeinfo) ) // dnt-policy.txt service (see https://www.eff.org/dnt-policy) staticRouter.use('/.well-known/dnt-policy.txt', - asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.DNT_POLICY)), + cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY), (_, res: express.Response) => { res.type('text/plain')