diff options
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts new file mode 100644 index 000000000..51f75c57e --- /dev/null +++ b/server/controllers/static.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import express = require('express') | ||
2 | import cors = require('cors') | ||
3 | |||
4 | import { | ||
5 | CONFIG, | ||
6 | STATIC_MAX_AGE, | ||
7 | STATIC_PATHS | ||
8 | } from '../initializers' | ||
9 | |||
10 | const staticRouter = express.Router() | ||
11 | |||
12 | /* | ||
13 | Cors is very important to let other pods access torrent and video files | ||
14 | */ | ||
15 | |||
16 | const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR | ||
17 | staticRouter.use( | ||
18 | STATIC_PATHS.TORRENTS, | ||
19 | cors(), | ||
20 | express.static(torrentsPhysicalPath, { maxAge: STATIC_MAX_AGE }) | ||
21 | ) | ||
22 | |||
23 | // Videos path for webseeding | ||
24 | const videosPhysicalPath = CONFIG.STORAGE.VIDEOS_DIR | ||
25 | staticRouter.use( | ||
26 | STATIC_PATHS.WEBSEED, | ||
27 | cors(), | ||
28 | express.static(videosPhysicalPath, { maxAge: STATIC_MAX_AGE }) | ||
29 | ) | ||
30 | |||
31 | // Thumbnails path for express | ||
32 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR | ||
33 | staticRouter.use( | ||
34 | STATIC_PATHS.THUMBNAILS, | ||
35 | express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE }) | ||
36 | ) | ||
37 | |||
38 | // Video previews path for express | ||
39 | const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR | ||
40 | staticRouter.use( | ||
41 | STATIC_PATHS.PREVIEWS, | ||
42 | express.static(previewsPhysicalPath, { maxAge: STATIC_MAX_AGE }) | ||
43 | ) | ||
44 | |||
45 | // --------------------------------------------------------------------------- | ||
46 | |||
47 | export { | ||
48 | staticRouter | ||
49 | } | ||