-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
38 lines (27 loc) · 813 Bytes
/
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
var Adapter = require('../adapter')
, connect = require('connect')
, http = require('http');
var Server = function (peak, options) {
this.peak = peak;
this.options = options || {};
this.emitter = peak.emitter;
this.path = options.output_path;
this.port = options.port || 1111;
this.index = options.index;
if (extension = Adapter.extension({path: this.index})) {
this.index = this.index.replace(/.([a-zA-Z]*)$/, extension);
}
this.app = connect()
.use(connect.static(this.path, {index: this.index}));
this.server = http.createServer(this.app);
}
Server.prototype = {
start: function () {
this.emitter.emit('start', 'server on port ' + this.port);
this.server.listen(this.port);
},
stop: function () {
this.server.close();
}
}
module.exports = Server;