1 | var express = require("express"); |
---|
2 | var fs = require("fs"); |
---|
3 | var https = require("https"); |
---|
4 | var os = require("os"); |
---|
5 | var path = require("path"); |
---|
6 | var proxy = require("simple-http-proxy"); |
---|
7 | var _ = require("underscore"); |
---|
8 | |
---|
9 | function clientPath(relativePath) { |
---|
10 | return path.resolve('../client/'+relativePath); |
---|
11 | } |
---|
12 | |
---|
13 | var httpsOptions = { |
---|
14 | key: fs.readFileSync(path.resolve('../qed-server.key')), |
---|
15 | cert: fs.readFileSync(path.resolve('../qed-server.pem')) |
---|
16 | }; |
---|
17 | |
---|
18 | var app = express(); |
---|
19 | app.use(express.logger()); |
---|
20 | app.use(express.compress()); |
---|
21 | app.use(express.favicon()); |
---|
22 | app.get('/', function(request, response){ |
---|
23 | response.sendfile(clientPath('index.html')); |
---|
24 | }); |
---|
25 | app.get('/*.html', function(request, response) { |
---|
26 | response.sendfile(clientPath(request.path)); |
---|
27 | }); |
---|
28 | _.each(['/dojo', '/dijit', '/dojox', '/qed', '/qed-client'], function(dir){ |
---|
29 | app.use(dir, express.static(clientPath(dir))); |
---|
30 | }); |
---|
31 | app.use('/data/couch', proxy('http://localhost:5984/qed')); |
---|
32 | |
---|
33 | var server = https.createServer(httpsOptions, app) |
---|
34 | server.listen(8443); |
---|
35 | |
---|
36 | console.log( |
---|
37 | "Listening on " + |
---|
38 | _.chain(os.networkInterfaces()) |
---|
39 | .map(function(value,key){ return value; }) |
---|
40 | .flatten() |
---|
41 | .filter(function(intf){ return intf.family === "IPv4" && !intf.internal; }) |
---|
42 | .reduce(function(urls, intf){ return urls+', http://'+intf.address+':8443/'; }, "http://127.0.0.1:8443/") |
---|
43 | .value() + "."); |
---|