-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 1.16 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
const path = require('path');
const express = require('express');
const cookierParser = require('cookie-parser');
const api = require('./api')
const auth = require('./auth')
const app = express();
const port = process.env.PORT || 8080;
const hostname = process.env.HOSTNAME || '127.0.0.1';
app.disable('etag');
app.use(express.urlencoded());
app.use(express.json());
app.use(cookierParser('abcdef-12345'))
app.use(express.static(path.join(__dirname, '/public')));
app.get('/*', function(req, res, next){
res.setHeader('Last-Modified', (new Date()).toUTCString());
next();
});
app.get('/', api.showHtml('public/index.html'));
app.get('/hello', api.helloWorld);
app.get('/register', api.showHtml('public/register.html'));
app.get('/login', auth.validateToken, api.checkLoggedIn, api.showHtml('public/login.html'));
app.post('/login', api.login);
app.get('/success', auth.authenticateToken,api.showHtml('public/success.html'));
app.post('/logout', api.logout);
app.get('/secret', auth.authenticateToken, api.showHtml('public/secret.html'));
app.post('/message', api.message)
app.listen(port, hostname, () => console.log(`Server started at http://${hostname}:${port}/`));