2014-06-02 14:00:24 -07:00
|
|
|
var express = require('express');
|
2014-06-24 08:36:32 -07:00
|
|
|
var http = require('http');
|
|
|
|
var app = express();
|
2014-04-20 12:46:03 -07:00
|
|
|
|
2014-12-19 14:10:34 -08:00
|
|
|
// This is not really necesarry, just to simulate
|
|
|
|
// Content Security Policy from Google Chrome Apps.
|
|
|
|
//
|
|
|
|
// app.use(function(req, res, next){
|
|
|
|
// res.header("Content-Security-Policy", "script-src 'self';object-src 'none';media-src 'self';frame-src 'none';font-src 'self' data:");
|
|
|
|
// next();
|
|
|
|
// });
|
|
|
|
|
2014-07-16 13:59:28 -07:00
|
|
|
app.use('/', express.static(__dirname + '/'));
|
|
|
|
app.get('*', function(req, res) {
|
2014-11-12 07:10:46 -08:00
|
|
|
return res.sendFile(__dirname + '/' + 'index.html');
|
2014-07-16 13:59:28 -07:00
|
|
|
});
|
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
app.start = function(port, callback) {
|
2014-04-20 12:46:03 -07:00
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
app.set('port', port);
|
|
|
|
app.use(express.static(__dirname));
|
2014-04-20 12:46:03 -07:00
|
|
|
|
2014-07-30 19:14:29 -07:00
|
|
|
if (process.env.USE_HTTPS) {
|
|
|
|
var path = require('path');
|
2014-08-04 10:59:35 -07:00
|
|
|
|
2014-07-30 19:14:29 -07:00
|
|
|
var bc = path.dirname(require.resolve('bitcore/package.json'));
|
|
|
|
var pserver = require(bc + '/examples/PayPro/server.js');
|
2014-08-04 10:59:35 -07:00
|
|
|
|
2014-07-31 11:00:22 -07:00
|
|
|
pserver.removeListener('request', pserver.app);
|
2014-08-04 10:59:35 -07:00
|
|
|
|
2014-09-15 18:51:12 -07:00
|
|
|
// pserver.options['no-tx'] = true;
|
|
|
|
// pserver.options['discovery'] = true;
|
|
|
|
|
2014-07-31 11:00:22 -07:00
|
|
|
pserver.on('request', function(req, res) {
|
2014-07-31 14:41:50 -07:00
|
|
|
if (req.url.indexOf('/-/') === 0) {
|
|
|
|
return pserver.app(req, res);
|
|
|
|
}
|
2014-07-31 11:00:22 -07:00
|
|
|
return app(req, res);
|
2014-07-30 19:14:29 -07:00
|
|
|
});
|
2014-08-04 10:59:35 -07:00
|
|
|
|
2014-07-31 11:00:22 -07:00
|
|
|
pserver.listen(port, function() {
|
2014-07-30 19:14:29 -07:00
|
|
|
callback('https://localhost:' + port);
|
|
|
|
});
|
2014-08-04 10:59:35 -07:00
|
|
|
|
2014-07-30 19:14:29 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
app.listen(port, function() {
|
|
|
|
callback('http://localhost:' + port);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = app;
|
2014-06-06 11:23:40 -07:00
|
|
|
|