diff options
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 47 |
1 files changed, 16 insertions, 31 deletions
@@ -34,10 +34,7 @@ const customValidators = require('./server/helpers/custom-validators') | |||
34 | const installer = require('./server/initializers/installer') | 34 | const installer = require('./server/initializers/installer') |
35 | const mongoose = require('mongoose') | 35 | const mongoose = require('mongoose') |
36 | const routes = require('./server/controllers') | 36 | const routes = require('./server/controllers') |
37 | const utils = require('./server/helpers/utils') | ||
38 | const webtorrent = require('./server/lib/webtorrent') | ||
39 | const Request = mongoose.model('Request') | 37 | const Request = mongoose.model('Request') |
40 | const Video = mongoose.model('Video') | ||
41 | 38 | ||
42 | // Get configurations | 39 | // Get configurations |
43 | const port = config.get('listen.port') | 40 | const 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 | ||
72 | const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents')) | ||
73 | app.use(constants.STATIC_PATHS.TORRENTS, express.static(torrentsPhysicalPath, { maxAge: 0 })) | ||
74 | |||
75 | // Uploads path for webseeding | ||
76 | const uploadsPhysicalPath = path.join(__dirname, config.get('storage.uploads')) | ||
77 | app.use(constants.STATIC_PATHS.WEBSEED, express.static(uploadsPhysicalPath, { maxAge: 0 })) | ||
78 | |||
75 | // Thumbnails path for express | 79 | // Thumbnails path for express |
76 | const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) | 80 | const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) |
77 | app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) | 81 | app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) |
78 | 82 | ||
79 | // Client application | 83 | // Client application |
80 | app.use('/*', function (req, res, next) { | 84 | app.use('/*', function (req, res, next) { |
@@ -121,33 +125,14 @@ app.use(function (err, req, res, next) { | |||
121 | installer.installApplication(function (err) { | 125 | installer.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 | ||