-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 960 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const { inviteCode } = require('./secret');
const app = express();
app.use(bodyParser.json());
const PORT = 5001;
const LOG_RUNNING_ON_PORT = 'Running on port: %s';
function createAdmin(user) { }
function createUser(user) { }
const baseUser = { picture: 'default.png' };
app.post('/api/createUser', (req, res) => {
let user = null;
try {
user = req.body;
if (user.isAdmin && user.inviteCode !== inviteCode) {
throw new Error('No invite code? No admin!');
} else {
let newUser = Object.assign(baseUser, user);
if (newUser.isAdmin) createAdmin(newUser)
else createUser(newUser);
res.send('Successfully created ' +
`${newUser.isAdmin ? 'Admin' : 'User'}`);
}
} catch (e) {
console.log(e);
res.send(e.message);
}
});
app.listen(PORT, () => console.log(LOG_RUNNING_ON_PORT, PORT));
module.exports = app