;(function () {
'use strict'
- var api = {}
- api.videos = require('./videos')
- api.remoteVideos = require('./remoteVideos')
- api.pods = require('./pods')
+ var express = require('express')
+ var router = express.Router()
- module.exports = api
+ router.use('/videos', require('./videos'))
+ router.use('/remotevideos', require('./remoteVideos'))
+ router.use('/pods', require('./pods'))
+
+ module.exports = router
})()
;(function () {
'use strict'
- function getPartial (req, res) {
- var directory = req.params.directory
- var name = req.params.name
-
- res.render('partials/' + directory + '/' + name)
- }
-
- function getIndex (req, res) {
- res.render('index')
+ var routes = {
+ api: require('./api/' + global.API_VERSION),
+ views: require('./views')
}
- var express = require('express')
- var middleware = require('../middlewares')
-
- var router = express.Router()
-
- router.get('/partials/:directory/:name', middleware.cache(), getPartial)
- router.get(/^\/(index)?$/, middleware.cache(), getIndex)
-
- module.exports = router
+ module.exports = routes
})()
--- /dev/null
+;(function () {
+ 'use strict'
+
+ function getPartial (req, res) {
+ var directory = req.params.directory
+ var name = req.params.name
+
+ res.render('partials/' + directory + '/' + name)
+ }
+
+ function getIndex (req, res) {
+ res.render('index')
+ }
+
+ var express = require('express')
+ var middleware = require('../middlewares')
+
+ var router = express.Router()
+
+ router.get('/partials/:directory/:name', middleware.cache(), getPartial)
+ router.get(/^\/(index)?$/, middleware.cache(), getIndex)
+
+ module.exports = router
+})()
var config = require('config')
var logger = require('./src/logger')
var routes = require('./routes')
- var api = require('./routes/api/' + global.API_VERSION)
var utils = require('./src/utils')
var videos = require('./src/videos')
var webtorrent = require('./src/webTorrentNode')
- var compression
var port = config.get('listen.port')
var uploads = config.get('storage.uploads')
// ----------- Views, routes and static files -----------
- if (process.env.NODE_ENV === 'production') {
- // logger.log('Production : static files in dist/\n')
-
- // GZip compression
- compression = require('compression')
- app.use(compression())
-
- // A month
- var maxAge = 86400000 * 30
-
- // TODO
- app.get(/^\/(index|(partials\/[a-z\/]+))?$/, function (req, res, next) {
- if (req.url === '/') {
- req.url = '/index'
- }
-
- req.url += '.html'
- next()
- })
-
- app.use(express.static(path.join(__dirname, '/dist/public'), { maxAge: maxAge }))
- app.use(express.static(path.join(__dirname, '/dist/views'), { maxAge: maxAge }))
- } else {
- // Livereload
- app.use(require('connect-livereload')({
- port: 35729
- }))
+ // Livereload
+ app.use(require('connect-livereload')({
+ port: 35729
+ }))
- require('segfault-handler').registerHandler()
+ require('segfault-handler').registerHandler()
- app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 }))
+ app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 }))
- // Jade template from ./views directory
- app.set('views', path.join(__dirname, '/views'))
- app.set('view engine', 'jade')
+ // Jade template from ./views directory
+ app.set('views', path.join(__dirname, '/views'))
+ app.set('view engine', 'jade')
- // Views routes
- app.use('/', routes)
- }
-
- // ----------- Routes -----------
+ // API
var api_route = '/api/' + global.API_VERSION
- app.use(api_route + '/videos', api.videos)
- app.use(api_route + '/remotevideos', api.remoteVideos)
- app.use(api_route + '/pods', api.pods)
+ app.use(api_route, routes.api)
+
+ // Views routes
+ app.use('/', routes.views)
// ----------- Tracker -----------