diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/client.js | 13 | ||||
-rw-r--r-- | server/controllers/index.js | 4 | ||||
-rw-r--r-- | server/controllers/static.js | 46 |
3 files changed, 60 insertions, 3 deletions
diff --git a/server/controllers/client.js b/server/controllers/client.js index 61e094980..572db6133 100644 --- a/server/controllers/client.js +++ b/server/controllers/client.js | |||
@@ -13,8 +13,9 @@ const Video = mongoose.model('Video') | |||
13 | const router = express.Router() | 13 | const router = express.Router() |
14 | 14 | ||
15 | const opengraphComment = '<!-- opengraph tags -->' | 15 | const opengraphComment = '<!-- opengraph tags -->' |
16 | const embedPath = path.join(__dirname, '../../client/dist/standalone/videos/embed.html') | 16 | const distPath = path.join(__dirname, '../../client/dist') |
17 | const indexPath = path.join(__dirname, '../../client/dist/index.html') | 17 | const embedPath = path.join(distPath, 'standalone/videos/embed.html') |
18 | const indexPath = path.join(distPath, 'index.html') | ||
18 | 19 | ||
19 | // Special route that add OpenGraph tags | 20 | // Special route that add OpenGraph tags |
20 | // Do not use a template engine for a so little thing | 21 | // Do not use a template engine for a so little thing |
@@ -24,6 +25,14 @@ router.use('/videos/embed', function (req, res, next) { | |||
24 | res.sendFile(embedPath) | 25 | res.sendFile(embedPath) |
25 | }) | 26 | }) |
26 | 27 | ||
28 | // Static HTML/CSS/JS client files | ||
29 | router.use('/client', express.static(distPath, { maxAge: constants.STATIC_MAX_AGE })) | ||
30 | |||
31 | // 404 for static files not found | ||
32 | router.use('/client/*', function (req, res, next) { | ||
33 | res.sendStatus(404) | ||
34 | }) | ||
35 | |||
27 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
28 | 37 | ||
29 | module.exports = router | 38 | module.exports = router |
diff --git a/server/controllers/index.js b/server/controllers/index.js index 90b481e52..c9ca297ef 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js | |||
@@ -2,8 +2,10 @@ | |||
2 | 2 | ||
3 | const apiController = require('./api/') | 3 | const apiController = require('./api/') |
4 | const clientController = require('./client') | 4 | const clientController = require('./client') |
5 | const staticController = require('./static') | ||
5 | 6 | ||
6 | module.exports = { | 7 | module.exports = { |
7 | api: apiController, | 8 | api: apiController, |
8 | client: clientController | 9 | client: clientController, |
10 | static: staticController | ||
9 | } | 11 | } |
diff --git a/server/controllers/static.js b/server/controllers/static.js new file mode 100644 index 000000000..a91ff044d --- /dev/null +++ b/server/controllers/static.js | |||
@@ -0,0 +1,46 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | const cors = require('cors') | ||
5 | |||
6 | const constants = require('../initializers/constants') | ||
7 | |||
8 | const router = express.Router() | ||
9 | |||
10 | /* | ||
11 | Cors is very important to let other pods access torrent and video files | ||
12 | */ | ||
13 | |||
14 | const torrentsPhysicalPath = constants.CONFIG.STORAGE.TORRENTS_DIR | ||
15 | router.use( | ||
16 | constants.STATIC_PATHS.TORRENTS, | ||
17 | cors(), | ||
18 | express.static(torrentsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }) | ||
19 | ) | ||
20 | |||
21 | // Videos path for webseeding | ||
22 | const videosPhysicalPath = constants.CONFIG.STORAGE.VIDEOS_DIR | ||
23 | router.use( | ||
24 | constants.STATIC_PATHS.WEBSEED, | ||
25 | cors(), | ||
26 | express.static(videosPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }) | ||
27 | ) | ||
28 | |||
29 | // Thumbnails path for express | ||
30 | const thumbnailsPhysicalPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR | ||
31 | router.use( | ||
32 | constants.STATIC_PATHS.THUMBNAILS, | ||
33 | express.static(thumbnailsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }) | ||
34 | ) | ||
35 | |||
36 | // Video previews path for express | ||
37 | const previewsPhysicalPath = constants.CONFIG.STORAGE.PREVIEWS_DIR | ||
38 | router.use( | ||
39 | constants.STATIC_PATHS.PREVIEWS, | ||
40 | express.static(previewsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }) | ||
41 | ) | ||
42 | |||
43 | // --------------------------------------------------------------------------- | ||
44 | |||
45 | module.exports = router | ||
46 | |||