]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/static.ts
Fix token injection if unlogged user
[github/Chocobozzz/PeerTube.git] / server / controllers / static.ts
CommitLineData
41fb13c3
C
1import cors from 'cors'
2import express from 'express'
3545e72c
C
3import {
4 asyncMiddleware,
5 ensureCanAccessPrivateVideoHLSFiles,
6 ensureCanAccessVideoPrivateWebTorrentFiles,
7 handleStaticError,
8 optionalAuthenticate
9} from '@server/middlewares'
ea8107bf 10import { CONFIG } from '../initializers/config'
3545e72c 11import { DIRECTORIES, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
65fcc311
C
12
13const staticRouter = express.Router()
14
ea8107bf 15// Cors is very important to let other servers access torrent and video files
62945f06
C
16staticRouter.use(cors())
17
3545e72c
C
18// WebTorrent/Classic videos
19staticRouter.use(
20 STATIC_PATHS.PRIVATE_WEBSEED,
21 optionalAuthenticate,
22 asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles),
23 express.static(DIRECTORIES.VIDEOS.PRIVATE, { fallthrough: false }),
24 handleStaticError
25)
65fcc311
C
26staticRouter.use(
27 STATIC_PATHS.WEBSEED,
3545e72c 28 express.static(DIRECTORIES.VIDEOS.PUBLIC, { fallthrough: false }),
f7ce623d 29 handleStaticError
65fcc311 30)
3545e72c 31
6040f87d 32staticRouter.use(
b9fffa29 33 STATIC_PATHS.REDUNDANCY,
f7ce623d
C
34 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }),
35 handleStaticError
6040f87d
C
36)
37
09209296 38// HLS
3545e72c
C
39staticRouter.use(
40 STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS,
41 optionalAuthenticate,
42 asyncMiddleware(ensureCanAccessPrivateVideoHLSFiles),
43 express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, { fallthrough: false }),
44 handleStaticError
45)
09209296 46staticRouter.use(
9c6ca37f 47 STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
3545e72c 48 express.static(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, { fallthrough: false }),
f7ce623d 49 handleStaticError
09209296
C
50)
51
65fcc311
C
52// Thumbnails path for express
53const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
54staticRouter.use(
55 STATIC_PATHS.THUMBNAILS,
f7ce623d
C
56 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }),
57 handleStaticError
65fcc311
C
58)
59
65fcc311
C
60// ---------------------------------------------------------------------------
61
62export {
63 staticRouter
64}