aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-11-07 18:22:05 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-11-07 18:22:05 +0100
commite85782f7da44267e11714a63567feb7e0127126e (patch)
tree75b385cd609180bdec773f028e423408e0b79819
parent34ca3b5225479a5da986c86ee4c42a73ae6df5ad (diff)
downloadPeerTube-e85782f7da44267e11714a63567feb7e0127126e.tar.gz
PeerTube-e85782f7da44267e11714a63567feb7e0127126e.tar.zst
PeerTube-e85782f7da44267e11714a63567feb7e0127126e.zip
Views refractoring
-rw-r--r--package.json1
-rw-r--r--routes/api/v1/index.js12
-rw-r--r--routes/index.js22
-rw-r--r--routes/views.js24
-rw-r--r--server.js56
5 files changed, 49 insertions, 66 deletions
diff --git a/package.json b/package.json
index 8ef7d1b9b..fbfa11d4e 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,6 @@
17 "blueimp-file-upload": "^9.10.1", 17 "blueimp-file-upload": "^9.10.1",
18 "body-parser": "^1.12.4", 18 "body-parser": "^1.12.4",
19 "bootstrap": "^3.3.5", 19 "bootstrap": "^3.3.5",
20 "compression": "^1.5.0",
21 "config": "^1.14.0", 20 "config": "^1.14.0",
22 "connect-livereload": "^0.5.3", 21 "connect-livereload": "^0.5.3",
23 "debug": "^2.2.0", 22 "debug": "^2.2.0",
diff --git a/routes/api/v1/index.js b/routes/api/v1/index.js
index 9a4ec8438..f5504ad85 100644
--- a/routes/api/v1/index.js
+++ b/routes/api/v1/index.js
@@ -1,10 +1,12 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var api = {} 4 var express = require('express')
5 api.videos = require('./videos') 5 var router = express.Router()
6 api.remoteVideos = require('./remoteVideos')
7 api.pods = require('./pods')
8 6
9 module.exports = api 7 router.use('/videos', require('./videos'))
8 router.use('/remotevideos', require('./remoteVideos'))
9 router.use('/pods', require('./pods'))
10
11 module.exports = router
10})() 12})()
diff --git a/routes/index.js b/routes/index.js
index 690913a84..ecca80721 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -1,24 +1,10 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 function getPartial (req, res) { 4 var routes = {
5 var directory = req.params.directory 5 api: require('./api/' + global.API_VERSION),
6 var name = req.params.name 6 views: require('./views')
7
8 res.render('partials/' + directory + '/' + name)
9 }
10
11 function getIndex (req, res) {
12 res.render('index')
13 } 7 }
14 8
15 var express = require('express') 9 module.exports = routes
16 var middleware = require('../middlewares')
17
18 var router = express.Router()
19
20 router.get('/partials/:directory/:name', middleware.cache(), getPartial)
21 router.get(/^\/(index)?$/, middleware.cache(), getIndex)
22
23 module.exports = router
24})() 10})()
diff --git a/routes/views.js b/routes/views.js
new file mode 100644
index 000000000..690913a84
--- /dev/null
+++ b/routes/views.js
@@ -0,0 +1,24 @@
1;(function () {
2 'use strict'
3
4 function getPartial (req, res) {
5 var directory = req.params.directory
6 var name = req.params.name
7
8 res.render('partials/' + directory + '/' + name)
9 }
10
11 function getIndex (req, res) {
12 res.render('index')
13 }
14
15 var express = require('express')
16 var middleware = require('../middlewares')
17
18 var router = express.Router()
19
20 router.get('/partials/:directory/:name', middleware.cache(), getPartial)
21 router.get(/^\/(index)?$/, middleware.cache(), getIndex)
22
23 module.exports = router
24})()
diff --git a/server.js b/server.js
index 317d8c3cd..3f68fff18 100644
--- a/server.js
+++ b/server.js
@@ -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