-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
73 lines (62 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
var debug = require('diagnostics')('browsenpm:server')
, Memory = require('memory-producer')
, BigPipe = require('bigpipe')
, connect = require('connect')
, config = require('./config')
, path = require('path');
//
// Setup all the configuration
//
var port = config.get('port')
, service = config.get('service');
//
// Initialize plugins and add a valid path to base for plugin-layout.
//
var watch = require('bigpipe-watch')
, layout = require('bigpipe-layout')
, godot = require('bigpipe-godot')
, probe = require('./plugins/npm-probe');
//
// Set base template and add default pagelets.
//
layout.options = {
base: path.join(__dirname, 'views', 'base.ejs'),
};
//
// Initialise the BigPipe server.
//
var pipe = new BigPipe(require('http').createServer(), {
pages: path.join(__dirname, 'pages'),
dist: path.join(__dirname, 'dist'),
godot: config.get('godot'),
plugins: [ probe, layout, watch, godot ],
transformer: 'sockjs'
});
//
// Add some producers to the godot client if it exists
//
if (pipe.godot) pipe.godot.add(new Memory({ service: service }));
//
// Add middleware.
//
pipe
.before(connect.static(path.join(__dirname, 'public')))
.before(connect.favicon(path.join(__dirname, 'public', 'favicon.png')));
//
// Listen for errors and the listen event.
//
pipe.on('error', function error(err) {
console.error('Browsenpm.org received an error:'+ err.message, err.stack);
});
pipe.once('listening', function listening() {
console.log('Browsenpm.org is now running on http://localhost:%d', port);
});
//
// Start listening when all data is properly prepared and fetched.
//
pipe.once('initialized', pipe.listen.bind(pipe, port));
//
// Expose the server.
//
module.exports = pipe;