X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server.js;h=6eb0220004b3a2f5238c3ae0333282415752162a;hb=72cb731c44e9ff848d9d4b7d0245f525d249c316;hp=5feb214764f183f10cd7f8b58e5407ff3ce0a98c;hpb=a6375e69668ea42e19531c6bc68dcd37f3f7cbd7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.js b/server.js index 5feb21476..6eb022000 100644 --- a/server.js +++ b/server.js @@ -10,11 +10,12 @@ const path = require('path') const TrackerServer = require('bittorrent-tracker').Server const WebSocketServer = require('ws').Server +process.title = 'peertube' + // Create our main app const app = express() // ----------- Database ----------- -const config = require('config') const constants = require('./server/initializers/constants') const database = require('./server/initializers/database') const logger = require('./server/helpers/logger') @@ -24,9 +25,14 @@ database.connect() // ----------- Checker ----------- const checker = require('./server/initializers/checker') -const miss = checker.checkConfig() -if (miss.length !== 0) { - throw new Error('Miss some configurations keys : ' + miss) +const missed = checker.checkMissedConfig() +if (missed.length !== 0) { + throw new Error('Miss some configurations keys : ' + missed) +} + +const errorMessage = checker.checkConfig() +if (errorMessage !== null) { + throw new Error(errorMessage) } // ----------- PeerTube modules ----------- @@ -37,9 +43,6 @@ const mongoose = require('mongoose') const routes = require('./server/controllers') const Request = mongoose.model('Request') -// Get configurations -const port = config.get('listen.port') - // ----------- Command line ----------- // ----------- App ----------- @@ -62,31 +65,19 @@ app.use(expressValidator({ // ----------- Views, routes and static files ----------- -// API routes +// API const apiRoute = '/api/' + constants.API_VERSION app.use(apiRoute, routes.api) -// Static files -app.use('/client', express.static(path.join(__dirname, '/client/dist'), { maxAge: 0 })) -// 404 for static files not found -app.use('/client/*', function (req, res, next) { - res.sendStatus(404) -}) +// Client files +app.use('/', routes.client) -const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents')) -app.use(constants.STATIC_PATHS.TORRENTS, express.static(torrentsPhysicalPath, { maxAge: 0 })) - -// Uploads path for webseeding -const uploadsPhysicalPath = path.join(__dirname, config.get('storage.uploads')) -app.use(constants.STATIC_PATHS.WEBSEED, express.static(uploadsPhysicalPath, { maxAge: 0 })) - -// Thumbnails path for express -const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails')) -app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: 0 })) +// Static files +app.use('/', routes.static) -// Client application +// Always serve index client page (the client is a single page application, let it handle routing) app.use('/*', function (req, res, next) { - res.sendFile(path.join(__dirname, 'client/dist/index.html')) + res.sendFile(path.join(__dirname, './client/dist/index.html')) }) // ----------- Tracker ----------- @@ -126,6 +117,9 @@ app.use(function (err, req, res, next) { res.sendStatus(err.status || 500) }) +// ----------- Run ----------- + +const port = constants.CONFIG.LISTEN.PORT installer.installApplication(function (err) { if (err) throw err @@ -138,8 +132,9 @@ installer.installApplication(function (err) { // Activate the pool requests Request.activate() - logger.info('Seeded all the videos') logger.info('Server listening on port %d', port) + logger.info('Webserver: %s', constants.CONFIG.WEBSERVER.URL) + app.emit('ready') }) })