]>
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 | ||
3545e72c C |
18 | // WebTorrent/Classic videos |
19 | staticRouter.use( | |
20 | STATIC_PATHS.PRIVATE_WEBSEED, | |
21 | optionalAuthenticate, | |
22 | asyncMiddleware(ensureCanAccessVideoPrivateWebTorrentFiles), | |
23 | express.static(DIRECTORIES.VIDEOS.PRIVATE, { fallthrough: false }), | |
24 | handleStaticError | |
25 | ) | |
65fcc311 C |
26 | staticRouter.use( |
27 | STATIC_PATHS.WEBSEED, | |
3545e72c | 28 | express.static(DIRECTORIES.VIDEOS.PUBLIC, { fallthrough: false }), |
f7ce623d | 29 | handleStaticError |
65fcc311 | 30 | ) |
3545e72c | 31 | |
6040f87d | 32 | staticRouter.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 |
39 | staticRouter.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 | 46 | staticRouter.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 |
53 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR | |
54 | staticRouter.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 | ||
62 | export { | |
63 | staticRouter | |
64 | } |