[451] | 1 | var express = require("express"); |
---|
| 2 | var fs = require("fs"); |
---|
| 3 | var https = require("https"); |
---|
[459] | 4 | var os = require("os"); |
---|
[451] | 5 | var path = require("path"); |
---|
| 6 | var proxy = require("simple-http-proxy"); |
---|
| 7 | var _ = require("underscore"); |
---|
[443] | 8 | |
---|
[452] | 9 | function clientPath(relativePath) { |
---|
| 10 | return path.resolve('../client/'+relativePath); |
---|
[451] | 11 | } |
---|
[443] | 12 | |
---|
[451] | 13 | var httpsOptions = { |
---|
[452] | 14 | key: fs.readFileSync(path.resolve('../qed-server.key')), |
---|
| 15 | cert: fs.readFileSync(path.resolve('../qed-server.pem')) |
---|
[451] | 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){ |
---|
[452] | 23 | response.sendfile(clientPath('index.html')); |
---|
[443] | 24 | }); |
---|
[452] | 25 | app.get('/*.html', function(request, response) { |
---|
| 26 | response.sendfile(clientPath(request.path)); |
---|
[451] | 27 | }); |
---|
[452] | 28 | _.each(['/dojo', '/dijit', '/dojox', '/qed', '/qed-client'], function(dir){ |
---|
| 29 | app.use(dir, express.static(clientPath(dir))); |
---|
| 30 | }); |
---|
[451] | 31 | app.use('/data/couch', proxy('http://localhost:5984/qed')); |
---|
| 32 | |
---|
[462] | 33 | var server = https.createServer(httpsOptions, app); |
---|
[459] | 34 | server.listen(8443); |
---|
[451] | 35 | |
---|
[459] | 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() + "."); |
---|