aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-11-16 13:54:00 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-11-16 13:54:00 +0100
commita18603803ae37d7db8ac116113ede0bd979eddcd (patch)
tree50c6a00159b0a34cdd2568753c214babf48ba2ba /server.js
parent16357143aeef68768664c8961db686e65b2350e2 (diff)
downloadPeerTube-a18603803ae37d7db8ac116113ede0bd979eddcd.tar.gz
PeerTube-a18603803ae37d7db8ac116113ede0bd979eddcd.tar.zst
PeerTube-a18603803ae37d7db8ac116113ede0bd979eddcd.zip
Source refractoring
Diffstat (limited to 'server.js')
-rw-r--r--server.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/server.js b/server.js
index 3f68fff18..715556414 100644
--- a/server.js
+++ b/server.js
@@ -1,20 +1,22 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 // ----------- Constantes ----------- 4 // ----------- Constants -----------
5 global.API_VERSION = 'v1' 5 global.API_VERSION = 'v1'
6 6
7 // ----------- Node modules ----------- 7 // ----------- Node modules -----------
8 var bodyParser = require('body-parser')
8 var express = require('express') 9 var express = require('express')
9 var expressValidator = require('express-validator') 10 var expressValidator = require('express-validator')
10 var path = require('path') 11 var http = require('http')
11 var morgan = require('morgan') 12 var morgan = require('morgan')
12 var bodyParser = require('body-parser')
13 var multer = require('multer') 13 var multer = require('multer')
14 var path = require('path')
14 var TrackerServer = require('bittorrent-tracker').Server 15 var TrackerServer = require('bittorrent-tracker').Server
15 var WebSocketServer = require('ws').Server 16 var WebSocketServer = require('ws').Server
17
18 // Create our main app
16 var app = express() 19 var app = express()
17 var http = require('http')
18 20
19 // ----------- Checker ----------- 21 // ----------- Checker -----------
20 var checker = require('./src/checker') 22 var checker = require('./src/checker')
@@ -26,7 +28,7 @@
26 process.exit(0) 28 process.exit(0)
27 } 29 }
28 30
29 checker.createDirectories() 31 checker.createDirectoriesIfNotExist()
30 32
31 // ----------- PeerTube modules ----------- 33 // ----------- PeerTube modules -----------
32 var config = require('config') 34 var config = require('config')
@@ -36,16 +38,22 @@
36 var videos = require('./src/videos') 38 var videos = require('./src/videos')
37 var webtorrent = require('./src/webTorrentNode') 39 var webtorrent = require('./src/webTorrentNode')
38 40
41 // Get configurations
39 var port = config.get('listen.port') 42 var port = config.get('listen.port')
40 var uploads = config.get('storage.uploads') 43 var uploads = config.get('storage.uploads')
41 44
42 // ----------- Command line ----------- 45 // ----------- Command line -----------
43 46
44 // ----------- App ----------- 47 // ----------- App -----------
48
49 // For the logger
45 app.use(morgan('combined', { stream: logger.stream })) 50 app.use(morgan('combined', { stream: logger.stream }))
51 // For body requests
46 app.use(bodyParser.json()) 52 app.use(bodyParser.json())
53 // For POST file requests
47 app.use(multer({ dest: uploads })) 54 app.use(multer({ dest: uploads }))
48 app.use(bodyParser.urlencoded({ extended: false })) 55 app.use(bodyParser.urlencoded({ extended: false }))
56 // Validate some params for the API
49 app.use(expressValidator()) 57 app.use(expressValidator())
50 58
51 // ----------- Views, routes and static files ----------- 59 // ----------- Views, routes and static files -----------
@@ -55,15 +63,17 @@
55 port: 35729 63 port: 35729
56 })) 64 }))
57 65
66 // Catch sefaults
58 require('segfault-handler').registerHandler() 67 require('segfault-handler').registerHandler()
59 68
69 // Static files
60 app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 })) 70 app.use(express.static(path.join(__dirname, '/public'), { maxAge: 0 }))
61 71
62 // Jade template from ./views directory 72 // Jade template from ./views directory
63 app.set('views', path.join(__dirname, '/views')) 73 app.set('views', path.join(__dirname, '/views'))
64 app.set('view engine', 'jade') 74 app.set('view engine', 'jade')
65 75
66 // API 76 // API routes
67 var api_route = '/api/' + global.API_VERSION 77 var api_route = '/api/' + global.API_VERSION
68 app.use(api_route, routes.api) 78 app.use(api_route, routes.api)
69 79