diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-07 10:10:00 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-07 10:10:00 +0200 |
commit | aff36eb063573532498979c83be1c279c84f2d53 (patch) | |
tree | 3f79dc7373689f0493e80a6e501225fd0cd7aa26 /server.js | |
parent | c3117f13d599f37693f937865b6e84eb1f72d5c4 (diff) | |
parent | a6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (diff) | |
download | PeerTube-aff36eb063573532498979c83be1c279c84f2d53.tar.gz PeerTube-aff36eb063573532498979c83be1c279c84f2d53.tar.zst PeerTube-aff36eb063573532498979c83be1c279c84f2d53.zip |
Merge branch 'webseed'
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 47 |
1 files changed, 16 insertions, 31 deletions
@@ -35,10 +35,7 @@ const installer = require('./server/initializers/installer') | |||
35 | const migrator = require('./server/initializers/migrator') | 35 | const migrator = require('./server/initializers/migrator') |
36 | const mongoose = require('mongoose') | 36 | const mongoose = require('mongoose') |
37 | const routes = require('./server/controllers') | 37 | const routes = require('./server/controllers') |
38 | const utils = require('./server/helpers/utils') | ||
39 | const webtorrent = require('./server/lib/webtorrent') | ||
40 | const Request = mongoose.model('Request') | 38 | const Request = mongoose.model('Request') |
41 | const Video = mongoose.model('Video') | ||
42 | 39 | ||
43 | // Get configurations | 40 | // Get configurations |
44 | const port = config.get('listen.port') | 41 | const port = config.get('listen.port') |
@@ -76,9 +73,16 @@ app.use('/client/*', function (req, res, next) { | |||
76 | res.sendStatus(404) | 73 | res.sendStatus(404) |
77 | }) | 74 | }) |
78 | 75 | ||
76 | const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents')) | ||
77 | app.use(constants.STATIC_PATHS.TORRENTS, express.static(torrentsPhysicalPath, { maxAge: 0 })) | ||
78 | |||
79 | // Uploads path for webseeding | ||
80 | const uploadsPhysicalPath = path.join(__dirname, config.get('storage.uploads')) | ||
81 | app.use(constants.STATIC_PATHS.WEBSEED, express.static(uploadsPhysicalPath, { maxAge: 0 })) | ||
82 | |||
79 | // Thumbnails path for express | 83 | // Thumbnails path for express |
80 | const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) | 84 | const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) |
81 | app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) | 85 | app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) |
82 | 86 | ||
83 | // Client application | 87 | // Client application |
84 | app.use('/*', function (req, res, next) { | 88 | app.use('/*', function (req, res, next) { |
@@ -129,33 +133,14 @@ installer.installApplication(function (err) { | |||
129 | migrator.migrate(function (err) { | 133 | migrator.migrate(function (err) { |
130 | if (err) throw err | 134 | if (err) throw err |
131 | 135 | ||
132 | // Create/activate the webtorrent module | 136 | // ----------- Make the server listening ----------- |
133 | webtorrent.create(function () { | 137 | server.listen(port, function () { |
134 | function cleanForExit () { | 138 | // Activate the pool requests |
135 | utils.cleanForExit(webtorrent.app) | 139 | Request.activate() |
136 | } | 140 | |
137 | 141 | logger.info('Seeded all the videos') | |
138 | function exitGracefullyOnSignal () { | 142 | logger.info('Server listening on port %d', port) |
139 | process.exit(-1) | 143 | app.emit('ready') |
140 | } | ||
141 | |||
142 | process.on('exit', cleanForExit) | ||
143 | process.on('SIGINT', exitGracefullyOnSignal) | ||
144 | process.on('SIGTERM', exitGracefullyOnSignal) | ||
145 | |||
146 | // ----------- Make the server listening ----------- | ||
147 | server.listen(port, function () { | ||
148 | // Activate the pool requests | ||
149 | Request.activate() | ||
150 | |||
151 | Video.seedAllExisting(function (err) { | ||
152 | if (err) throw err | ||
153 | |||
154 | logger.info('Seeded all the videos') | ||
155 | logger.info('Server listening on port %d', port) | ||
156 | app.emit('ready') | ||
157 | }) | ||
158 | }) | ||
159 | }) | 144 | }) |
160 | }) | 145 | }) |
161 | }) | 146 | }) |