-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (37 loc) · 948 Bytes
/
Copy pathindex.js
File metadata and controls
42 lines (37 loc) · 948 Bytes
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
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const user = require('./db/user')
const app = express()
app.use(morgan('tiny'))
app.use(cors())
app.use(bodyParser.json())
app.post('/user/register', (req, res) => {
console.log('hello')
user.register(req)
.then(response => {
res.json(response)
})
.catch(error => {
console.log(error)
res.status(error.status || 400).json(error.message)
})
})
app.post('/user/checkusername', (req, res) => {
user.checkUsername(req).then(message => res.json(message))
})
app.post('/user/login', (req, res) => {
user
.login(req)
.then(response => {
res.json(response)
})
.catch(error => {
res.status(error.status || 403).json(error.message)
})
})
const port = process.env.PORT || 4000
app.listen(port, () => {
console.log(`listening on ${port}`)
})