forked from rmurphey/js-assessment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 847 Bytes
/
server.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
var express = require('express'),
fs = require('fs'),
_ = require('underscore'),
site = express.createServer(),
staticDir = express['static'];
module.exports = function(opts) {
opts = _.extend({
port : 4444,
baseDir : './'
}, opts || {});
site.configure(function() {
[ 'app', 'lib', 'tests', 'data', 'answers' ].forEach(function(dir) {
site.use('/' + dir, staticDir(opts.baseDir + dir));
});
site.use(express.bodyParser());
});
site.get("/", function(req, res) {
fs.createReadStream(opts.baseDir + 'tests/runner.html').pipe(res);
});
site.listen(opts.port);
fs.readFile(opts.baseDir + 'help.txt', 'utf-8', function(err, f) {
console.log(f.replace('{{port}}', opts.port));
console.log("\n\nServing at http://localhost:" + opts.port);
});
};