-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (39 loc) · 1.02 KB
/
index.js
File metadata and controls
48 lines (39 loc) · 1.02 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
const SwaggerExpress = require('swagger-express-mw');
const express = require('express')
const bodyParser = require('body-parser')
const store = require('./store')
const app = express()
const config = {
appRoot: __dirname // required config
};
app.use(bodyParser.json())
app.post('/createUser', (req, res) => {
store
.createUser({
username: req.body.username,
password: req.body.password
})
.then(() => res.sendStatus(200))
})
app.post('/login', (req, res) => {
store
.authenticate({
username: req.body.username,
password: req.body.password
})
.then(({ success }) => {
if (success) res.sendStatus(200)
else res.sendStatus(401)
})
})
// app.listen(7555, () => {
// console.log('Server running on http://localhost:7555')
// })
SwaggerExpress.create(config, function (err, swaggerExpress) {
if (err) { throw err; }
// install middleware
swaggerExpress.register(app);
app.listen(7555, () => {
console.log('Server running on http://localhost:7555')
})
});