36 lines
982 B
JavaScript
36 lines
982 B
JavaScript
const express = require('express')
|
|
const bodyParser = require('body-parser');
|
|
const list = require("./listManager.js");
|
|
const app = express()
|
|
|
|
app.use(bodyParser.json(),function (req, res, next) {
|
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST')
|
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
|
|
res.setHeader('Content-Type', 'application/json')
|
|
res.setHeader('Access-Control-Allow-Credentials', true)
|
|
next()
|
|
})
|
|
|
|
|
|
|
|
app.get('/status/:status', function (req, res) {
|
|
list.getStatus(req.params.status).then(r => {
|
|
res.send(JSON.stringify(r))
|
|
})
|
|
})
|
|
|
|
app.get('/account/:username', function (req, res) {
|
|
list.getUser(req.params.username).then(r => {
|
|
res.send(JSON.stringify(r))
|
|
})
|
|
})
|
|
|
|
app.post('/submit', function (req, res) {
|
|
console.log(req.body)
|
|
list.writeUser(req.body).then(r => {
|
|
res.send(JSON.stringify(r))
|
|
})
|
|
})
|
|
app.listen(3000)
|