Files
  • index.js
  • db.js
  • package-lock.json
  • package.json
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
const express = require('express');
const bodyParser = require('body-parser');
const db = require('./db');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const urlencodedParser=bodyParser.urlencoded({extended:false});
app.use(express.static('public'));
app.use((req,res,next)=>{
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    //Copied from enable-cors.org
    next();
})
async function postMessage(key,message){
    db.collection("keywords").doc("")
}
app.post('/post',urlencodedParser, async (req, res) => {
    if(req.body.hasOwnProperty("keyword")&&req.body.hasOwnProperty("message")){
	    let error=await postMessage(req.body.keyword,req.body.message);
        res.send({result:"Hey, that worked!",error});
    }
    else{
        res.send({error:"Request must include a keyword and a message."});
    }
});

app.listen(3000, () => console.log('server started'));
node v9.7.1 linux/amd64