]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/static.ts
7668ceb82c822bd400c844378afde40b7ed69d04
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
1 import cors from 'cors'
2 import express from 'express'
3 import { CONFIG } from '../initializers/config'
4 import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
5
6 const staticRouter = express.Router()
7
8 // Cors is very important to let other servers access torrent and video files
9 staticRouter.use(cors())
10
11 // Videos path for webseed
12 staticRouter.use(
13 STATIC_PATHS.WEBSEED,
14 express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }) // 404 because we don't have this video
15 )
16 staticRouter.use(
17 STATIC_PATHS.REDUNDANCY,
18 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }) // 404 because we don't have this video
19 )
20
21 // HLS
22 staticRouter.use(
23 STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
24 express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }) // 404 if the file does not exist
25 )
26
27 // Thumbnails path for express
28 const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
29 staticRouter.use(
30 STATIC_PATHS.THUMBNAILS,
31 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist
32 )
33
34 // ---------------------------------------------------------------------------
35
36 export {
37 staticRouter
38 }