-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (42 loc) · 1.33 KB
/
server.js
File metadata and controls
57 lines (42 loc) · 1.33 KB
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
const auth = require('./auth');
const bodyParser = require('body-parser');
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const protocol = require('http');
const serveStatic = require('serve-static');
const util = require('util');
// EXPRESS STUFF
const app = express();
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(serveStatic(path.join(__dirname, '.')));
app.use(auth.init());
// API ROUTES
app.post('/signin', auth.isSignedOut, (req, res, next) => {
auth.signInViaMail(req, res, next, (err, username, token) => {
if (err) {
console.log(util.inspect(err));
return res.status(400).json(err);
} else {
return res.status(200).json({username: username, token: token});
}
});
});
app.post('/keepsession', auth.isSignedIn, (req, res) => {
res.json({username: req.user.username});
});
app.get('/user/profile', auth.isSignedIn, (req, res) => {
res.json({realName: req.user.realName});
});
app.all('*', function (req, res) {
return res.sendFile(path.join(__dirname, './views/index.html'));
});
// CREATE SERVER
const server = protocol.createServer(app);
server.listen(9090, '0.0.0.0', function () {
console.log('Server application started');
});