-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.js
77 lines (59 loc) · 2.08 KB
/
app.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
const http = require('http');
const fs = require('fs');
const express = require('express')
const path = require('path');
var bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json())
app.use(express.static(path.resolve(`${__dirname}/web/public`)));
console.log(`${__dirname}/web`);
app.use('*', (req, res, next) => {
console.log(`URL: ${req.baseUrl}`);
next();
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept,X-access-token');
next();
});
app.use((err, req, res, next) => {
if (err) {
res.send(err);
}
});
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.use(express.static(__dirname + '/views/web/public'));
var currentContract = 0;
app.get('/', (req, res, next) => {
currentContract = 0;
res.render('web/public/index.html');
});
app.get('/contractpage', (req, res, next) => {
res.render('web/public/contract.html', {currentContract:currentContract});
})
app.post('/initatecontract', (req, res, next) => {
currentContract = req.body.contractaddress;
res.render('web/public/contract.html', {currentContract:currentContract});
});
app.post('/init', (req, res, next) => {
res.render('web/public/init.html', {currentContract:currentContract});
});
app.post('/deposit', (req, res, next) => {
res.render('web/public/deposit.html', {currentContract:currentContract});
});
app.post('/approve', (req, res, next) => {
res.render('web/public/approve.html', {currentContract:currentContract});
});
app.post('/cancel', (req, res, next) => {
res.render('web/public/cancel.html', {currentContract:currentContract});
});
app.post('/end', (req, res, next) => {
res.render('web/public/end.html', {currentContract:currentContract});
});
var server = http.createServer(app);
server.listen(3000, function () {
console.log('Example app listening on port 3000!')
})