1 import { HttpStatusCode } from '@shared/models'
2 import cors from 'cors'
3 import express from 'express'
4 import { CONFIG } from '../initializers/config'
5 import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
7 const staticRouter = express.Router()
9 // Cors is very important to let other servers access torrent and video files
10 staticRouter.use(cors())
12 // Videos path for webseed
15 express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }),
19 STATIC_PATHS.REDUNDANCY,
20 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }),
26 STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
27 express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }),
31 // Thumbnails path for express
32 const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
34 STATIC_PATHS.THUMBNAILS,
35 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }),
39 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
48 const message = err.message || ''
50 if (message.includes('ENOENT')) {
52 status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,