// ----------- Node modules -----------
const bodyParser = require('body-parser')
+const cors = require('cors')
const express = require('express')
const expressValidator = require('express-validator')
const http = require('http')
// ----------- PeerTube modules -----------
const customValidators = require('./server/helpers/custom-validators')
const installer = require('./server/initializers/installer')
+const migrator = require('./server/initializers/migrator')
const mongoose = require('mongoose')
const routes = require('./server/controllers')
-const utils = require('./server/helpers/utils')
-const webtorrent = require('./server/lib/webtorrent')
const Request = mongoose.model('Request')
-const Video = mongoose.model('Video')
// Get configurations
const port = config.get('listen.port')
// For the logger
app.use(morgan('combined', { stream: logger.stream }))
// For body requests
-app.use(bodyParser.json())
+app.use(bodyParser.json({ limit: '500kb' }))
app.use(bodyParser.urlencoded({ extended: false }))
// Validate some params for the API
app.use(expressValidator({
- customValidators: Object.assign({}, customValidators.misc, customValidators.users, customValidators.videos)
+ customValidators: Object.assign(
+ {},
+ customValidators.misc,
+ customValidators.pods,
+ customValidators.users,
+ customValidators.videos
+ )
}))
// ----------- Views, routes and static files -----------
-// Catch sefaults
-require('segfault-handler').registerHandler()
-
// API routes
const apiRoute = '/api/' + constants.API_VERSION
app.use(apiRoute, routes.api)
res.sendStatus(404)
})
+const torrentsPhysicalPath = path.join(__dirname, config.get('storage.torrents'))
+app.use(constants.STATIC_PATHS.TORRENTS, cors(), express.static(torrentsPhysicalPath, { maxAge: '7d' }))
+
+// Videos path for webseeding
+const videosPhysicalPath = path.join(__dirname, config.get('storage.videos'))
+app.use(constants.STATIC_PATHS.WEBSEED, cors(), express.static(videosPhysicalPath, { maxAge: '7d' }))
+
// Thumbnails path for express
const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails'))
-app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 }))
+app.use(constants.STATIC_PATHS.THUMBNAILS, express.static(thumbnailsPhysicalPath, { maxAge: '7d' }))
// Client application
app.use('/*', function (req, res, next) {
installer.installApplication(function (err) {
if (err) throw err
- // Create/activate the webtorrent module
- webtorrent.create(function () {
- function cleanForExit () {
- utils.cleanForExit(webtorrent.app)
- }
-
- function exitGracefullyOnSignal () {
- process.exit(-1)
- }
-
- process.on('exit', cleanForExit)
- process.on('SIGINT', exitGracefullyOnSignal)
- process.on('SIGTERM', exitGracefullyOnSignal)
+ // Run the migration scripts if needed
+ migrator.migrate(function (err) {
+ if (err) throw err
// ----------- Make the server listening -----------
server.listen(port, function () {
// Activate the pool requests
Request.activate()
- Video.seedAllExisting(function (err) {
- if (err) throw err
-
- logger.info('Seeded all the videos')
- logger.info('Server listening on port %d', port)
- app.emit('ready')
- })
+ logger.info('Seeded all the videos')
+ logger.info('Server listening on port %d', port)
+ app.emit('ready')
})
})
})