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