42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
const bodyParser = require('body-parser');
|
|
const list = require("./listManager.js");
|
|
const { response } = require('express');
|
|
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('/meta/blacklist', function (req, res) {
|
|
list.getAllBlack().then(r => {
|
|
res.send(JSON.stringify(r))
|
|
})
|
|
})
|
|
|
|
app.get('/meta/greylist', function (req, res) {
|
|
list.getAllGrey().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)
|