aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rw-r--r--server.js47
1 files changed, 16 insertions, 31 deletions
diff --git a/server.js b/server.js
index b2eeeff70..0033ed1db 100644
--- a/server.js
+++ b/server.js
@@ -34,10 +34,7 @@ const customValidators = require('./server/helpers/custom-validators')
34const installer = require('./server/initializers/installer') 34const installer = require('./server/initializers/installer')
35const mongoose = require('mongoose') 35const mongoose = require('mongoose')
36const routes = require('./server/controllers') 36const routes = require('./server/controllers')
37const utils = require('./server/helpers/utils')
38const webtorrent = require('./server/lib/webtorrent')
39const Request = mongoose.model('Request') 37const Request = mongoose.model('Request')
40const Video = mongoose.model('Video')
41 38
42// Get configurations 39// Get configurations
43const port = config.get('listen.port') 40const port = config.get('listen.port')
@@ -72,9 +69,16 @@ app.use('/client/*', function (req, res, next) {
72 res.sendStatus(404) 69 res.sendStatus(404)
73}) 70})
74 71
72const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents'))
73app.use(constants.STATIC_PATHS.TORRENTS, express.static(torrentsPhysicalPath, { maxAge: 0 }))
74
75// Uploads path for webseeding
76const uploadsPhysicalPath = path.join(__dirname, config.get('storage.uploads'))
77app.use(constants.STATIC_PATHS.WEBSEED, express.static(uploadsPhysicalPath, { maxAge: 0 }))
78
75// Thumbnails path for express 79// Thumbnails path for express
76const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) 80const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails'))
77app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) 81app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: 0 }))
78 82
79// Client application 83// Client application
80app.use('/*', function (req, res, next) { 84app.use('/*', function (req, res, next) {
@@ -121,33 +125,14 @@ app.use(function (err, req, res, next) {
121installer.installApplication(function (err) { 125installer.installApplication(function (err) {
122 if (err) throw err 126 if (err) throw err
123 127
124 // Create/activate the webtorrent module 128 // ----------- Make the server listening -----------
125 webtorrent.create(function () { 129 server.listen(port, function () {
126 function cleanForExit () { 130 // Activate the pool requests
127 utils.cleanForExit(webtorrent.app) 131 Request.activate()
128 } 132
129 133 logger.info('Seeded all the videos')
130 function exitGracefullyOnSignal () { 134 logger.info('Server listening on port %d', port)
131 process.exit(-1) 135 app.emit('ready')
132 }
133
134 process.on('exit', cleanForExit)
135 process.on('SIGINT', exitGracefullyOnSignal)
136 process.on('SIGTERM', exitGracefullyOnSignal)
137
138 // ----------- Make the server listening -----------
139 server.listen(port, function () {
140 // Activate the pool requests
141 Request.activate()
142
143 Video.seedAllExisting(function (err) {
144 if (err) throw err
145
146 logger.info('Seeded all the videos')
147 logger.info('Server listening on port %d', port)
148 app.emit('ready')
149 })
150 })
151 }) 136 })
152}) 137})
153 138