aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rw-r--r--server.js33
1 files changed, 8 insertions, 25 deletions
diff --git a/server.js b/server.js
index 16e27e852..6eb022000 100644
--- a/server.js
+++ b/server.js
@@ -2,7 +2,6 @@
2 2
3// ----------- Node modules ----------- 3// ----------- Node modules -----------
4const bodyParser = require('body-parser') 4const bodyParser = require('body-parser')
5const cors = require('cors')
6const express = require('express') 5const express = require('express')
7const expressValidator = require('express-validator') 6const expressValidator = require('express-validator')
8const http = require('http') 7const http = require('http')
@@ -66,35 +65,17 @@ app.use(expressValidator({
66 65
67// ----------- Views, routes and static files ----------- 66// ----------- Views, routes and static files -----------
68 67
69// API routes 68// API
70const apiRoute = '/api/' + constants.API_VERSION 69const apiRoute = '/api/' + constants.API_VERSION
71app.use(apiRoute, routes.api) 70app.use(apiRoute, routes.api)
72app.use('/', routes.client)
73
74// Static client files
75// TODO: move in client
76app.use('/client', express.static(path.join(__dirname, '/client/dist'), { maxAge: constants.STATIC_MAX_AGE }))
77// 404 for static files not found
78app.use('/client/*', function (req, res, next) {
79 res.sendStatus(404)
80})
81
82const torrentsPhysicalPath = constants.CONFIG.STORAGE.TORRENTS_DIR
83app.use(constants.STATIC_PATHS.TORRENTS, cors(), express.static(torrentsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }))
84 71
85// Videos path for webseeding 72// Client files
86const videosPhysicalPath = constants.CONFIG.STORAGE.VIDEOS_DIR 73app.use('/', routes.client)
87app.use(constants.STATIC_PATHS.WEBSEED, cors(), express.static(videosPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }))
88
89// Thumbnails path for express
90const thumbnailsPhysicalPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR
91app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }))
92 74
93// Video previews path for express 75// Static files
94const previewsPhysicalPath = constants.CONFIG.STORAGE.PREVIEWS_DIR 76app.use('/', routes.static)
95app.use(constants.STATIC_PATHS.PREVIEWS, express.static(previewsPhysicalPath, { maxAge: constants.STATIC_MAX_AGE }))
96 77
97// Always serve index client page 78// Always serve index client page (the client is a single page application, let it handle routing)
98app.use('/*', function (req, res, next) { 79app.use('/*', function (req, res, next) {
99 res.sendFile(path.join(__dirname, './client/dist/index.html')) 80 res.sendFile(path.join(__dirname, './client/dist/index.html'))
100}) 81})
@@ -136,6 +117,8 @@ app.use(function (err, req, res, next) {
136 res.sendStatus(err.status || 500) 117 res.sendStatus(err.status || 500)
137}) 118})
138 119
120// ----------- Run -----------
121
139const port = constants.CONFIG.LISTEN.PORT 122const port = constants.CONFIG.LISTEN.PORT
140installer.installApplication(function (err) { 123installer.installApplication(function (err) {
141 if (err) throw err 124 if (err) throw err