aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-07 10:10:00 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-07 10:10:00 +0200
commitaff36eb063573532498979c83be1c279c84f2d53 (patch)
tree3f79dc7373689f0493e80a6e501225fd0cd7aa26 /server.js
parentc3117f13d599f37693f937865b6e84eb1f72d5c4 (diff)
parenta6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (diff)
downloadPeerTube-aff36eb063573532498979c83be1c279c84f2d53.tar.gz
PeerTube-aff36eb063573532498979c83be1c279c84f2d53.tar.zst
PeerTube-aff36eb063573532498979c83be1c279c84f2d53.zip
Merge branch 'webseed'
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 ca275ccec..5feb21476 100644
--- a/server.js
+++ b/server.js
@@ -35,10 +35,7 @@ const installer = require('./server/initializers/installer')
35const migrator = require('./server/initializers/migrator') 35const migrator = require('./server/initializers/migrator')
36const mongoose = require('mongoose') 36const mongoose = require('mongoose')
37const routes = require('./server/controllers') 37const routes = require('./server/controllers')
38const utils = require('./server/helpers/utils')
39const webtorrent = require('./server/lib/webtorrent')
40const Request = mongoose.model('Request') 38const Request = mongoose.model('Request')
41const Video = mongoose.model('Video')
42 39
43// Get configurations 40// Get configurations
44const port = config.get('listen.port') 41const 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
76const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents'))
77app.use(constants.STATIC_PATHS.TORRENTS, express.static(torrentsPhysicalPath, { maxAge: 0 }))
78
79// Uploads path for webseeding
80const uploadsPhysicalPath = path.join(__dirname, config.get('storage.uploads'))
81app.use(constants.STATIC_PATHS.WEBSEED, express.static(uploadsPhysicalPath, { maxAge: 0 }))
82
79// Thumbnails path for express 83// Thumbnails path for express
80const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) 84const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails'))
81app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) 85app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: 0 }))
82 86
83// Client application 87// Client application
84app.use('/*', function (req, res, next) { 88app.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})