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