This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
79 lines (64 loc) · 2.09 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var http = require('http');
var express = require('express');
var i18n = require('i18n-abide');
var nunjucks = require('nunjucks');
var rewriteModule = require('http-rewrite-middleware');
var config = require('../config/');
var app = express();
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(__dirname + '/templates'),
{autoescape: true});
app.use(require('connect-livereload')({
port: config.liveReloadPort,
}));
env.express(app);
app.use(i18n.abide({
supported_languages: config.supportedLanguages,
debug_lang: 'db-LB',
default_lang: 'en-US',
translation_directory: 'public/i18n'
}));
app.use(rewriteModule.getMiddleware([
{from: '^/$', to: '/mozpay', redirect: 'permanent'},
{from: '^/mozpay/(?:login|create-pin|enter-pin|reset-pin|locked|throbber|was-locked)$', to: '/mozpay'},
]));
app.get(/\/(?:css|fonts|i18n|images|js|lib)\/?.*/, express.static(__dirname + '/../public'));
app.get('/mozpay', function (req, res) {
res.render('index.html', {settings: config});
});
// Serve test assets.
app.get(/\/testlib\/?.*/, express.static(__dirname + '/../tests/static'));
app.get(/\/unit\/?.*/, express.static(__dirname + '/../tests/'));
// Fake API response.
app.get('/mozpay/v1/api/pin/', function(req, res) {
var result = {
pin: false,
pin_is_locked_out: false,
pin_was_locked_out: false,
pin_locked_out: null
};
res.send(result);
});
// Fake verification.
app.post('/fake-verify', function (req, res) {
var assertion = req.query.assertion ? req.query.assertion : '';
var success = {
'status': 'okay',
'audience': 'http://localhost:' + config.test.port,
'expires': Date.now(),
'issuer': 'fake-persona'
};
success.email = assertion;
res.send(success);
});
// Fake logout
app.post('/logout', function (req, res) {
res.send({'msg': 'logout success'});
});
app.get('/unittests', function (req, res) {
res.render('test.html');
});
console.log('Starting DEV Server');
var port = process.env.PORT || config.port;
http.createServer(app).listen(port, function() {
console.log('listening on port: ' + port);
});