diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2015-11-07 18:22:05 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2015-11-07 18:22:05 +0100 |
commit | e85782f7da44267e11714a63567feb7e0127126e (patch) | |
tree | 75b385cd609180bdec773f028e423408e0b79819 /server.js | |
parent | 34ca3b5225479a5da986c86ee4c42a73ae6df5ad (diff) | |
download | PeerTube-e85782f7da44267e11714a63567feb7e0127126e.tar.gz PeerTube-e85782f7da44267e11714a63567feb7e0127126e.tar.zst PeerTube-e85782f7da44267e11714a63567feb7e0127126e.zip |
Views refractoring
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 56 |
1 files changed, 14 insertions, 42 deletions
@@ -32,12 +32,10 @@ | |||
32 | var config = require('config') | 32 | var config = require('config') |
33 | var logger = require('./src/logger') | 33 | var logger = require('./src/logger') |
34 | var routes = require('./routes') | 34 | var routes = require('./routes') |
35 | var api = require('./routes/api/' + global.API_VERSION) | ||
36 | var utils = require('./src/utils') | 35 | var utils = require('./src/utils') |
37 | var videos = require('./src/videos') | 36 | var videos = require('./src/videos') |
38 | var webtorrent = require('./src/webTorrentNode') | 37 | var webtorrent = require('./src/webTorrentNode') |
39 | 38 | ||
40 | var compression | ||
41 | var port = config.get('listen.port') | 39 | var port = config.get('listen.port') |
42 | var uploads = config.get('storage.uploads') | 40 | var uploads = config.get('storage.uploads') |
43 | 41 | ||
@@ -52,51 +50,25 @@ | |||
52 | 50 | ||
53 | // ----------- Views, routes and static files ----------- | 51 | // ----------- Views, routes and static files ----------- |
54 | 52 | ||
55 | if (process.env.NODE_ENV === 'production') { | 53 | // Livereload |
56 | // logger.log('Production : static files in dist/\n') | 54 | app.use(require('connect-livereload')({ |
57 | 55 | port: 35729 | |
58 | // GZip compression | 56 | })) |
59 | compression = require('compression') | ||
60 | app.use(compression()) | ||
61 | |||
62 | // A month | ||
63 | var maxAge = 86400000 * 30 | ||
64 | |||
65 | // TODO | ||
66 | app.get(/^\/(index|(partials\/[a-z\/]+))?$/, function (req, res, next) { | ||
67 | if (req.url === '/') { | ||
68 | req.url = '/index' | ||
69 | } | ||
70 | |||
71 | req.url += '.html' | ||
72 | next() | ||
73 | }) | ||
74 | |||
75 | app.use(express.static(path.join(__dirname, '/dist/public'), { maxAge: maxAge })) | ||
76 | app.use(express.static(path.join(__dirname, '/dist/views'), { maxAge: maxAge })) | ||
77 | } else { | ||
78 | // Livereload | ||
79 | app.use(require('connect-livereload')({ | ||
80 | port: 35729 | ||
81 | })) | ||
82 | 57 | ||
83 | require('segfault-handler').registerHandler() | 58 | require('segfault-handler').registerHandler() |
84 | 59 | ||
85 | app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 })) | 60 | app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 })) |
86 | 61 | ||
87 | // Jade template from ./views directory | 62 | // Jade template from ./views directory |
88 | app.set('views', path.join(__dirname, '/views')) | 63 | app.set('views', path.join(__dirname, '/views')) |
89 | app.set('view engine', 'jade') | 64 | app.set('view engine', 'jade') |
90 | 65 | ||
91 | // Views routes | 66 | // API |
92 | app.use('/', routes) | ||
93 | } | ||
94 | |||
95 | // ----------- Routes ----------- | ||
96 | var api_route = '/api/' + global.API_VERSION | 67 | var api_route = '/api/' + global.API_VERSION |
97 | app.use(api_route + '/videos', api.videos) | 68 | app.use(api_route, routes.api) |
98 | app.use(api_route + '/remotevideos', api.remoteVideos) | 69 | |
99 | app.use(api_route + '/pods', api.pods) | 70 | // Views routes |
71 | app.use('/', routes.views) | ||
100 | 72 | ||
101 | // ----------- Tracker ----------- | 73 | // ----------- Tracker ----------- |
102 | 74 | ||