@426729/

Personal Postbin

Express

No description

fork
loading
Files
  • index.js
  • db.js
  • package-lock.json
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.47151244310797935","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgZXhwcmVzcyA9IHJlcXVpcmUoJ2V4cHJlc3MnKTsKY29uc3QgYm9keVBhcnNlciA9IHJlcXVpcmUoJ2JvZHktcGFyc2VyJyk7CmNvbnN0IGRiID0gcmVxdWlyZSgnLi9kYicpOwpjb25zdCBhcHAgPSBleHByZXNzKCk7CgphcHAudXNlKGJvZHlQYXJzZXIuanNvbigpKTsKYXBwLnVzZShib2R5UGFyc2VyLnVybGVuY29kZWQoeyBleHRlbmRlZDogdHJ1ZSB9KSk7CmNvbnN0IHVybGVuY29kZWRQYXJzZXI9Ym9keVBhcnNlci51cmxlbmNvZGVkKHtleHRlbmRlZDpmYWxzZX0pOwphcHAudXNlKGV4cHJlc3Muc3RhdGljKCdwdWJsaWMnKSk7CmFwcC51c2UoKHJlcSxyZXMsbmV4dCk9PnsKICAgIHJlcy5oZWFkZXIoIkFjY2Vzcy1Db250cm9sLUFsbG93LU9yaWdpbiIsICIqIik7CiAgICByZXMuaGVhZGVyKCJBY2Nlc3MtQ29udHJvbC1BbGxvdy1IZWFkZXJzIiwgIk9yaWdpbiwgWC1SZXF1ZXN0ZWQtV2l0aCwgQ29udGVudC1UeXBlLCBBY2NlcHQiKTsKICAgIC8vQ29waWVkIGZyb20gZW5hYmxlLWNvcnMub3JnCiAgICBuZXh0KCk7Cn0pCmFzeW5jIGZ1bmN0aW9uIHBvc3RNZXNzYWdlKGtleSxtZXNzYWdlKXsKICAgIGRiLmNvbGxlY3Rpb24oImtleXdvcmRzIikuZG9jKCIiKQp9CmFwcC5wb3N0KCcvcG9zdCcsdXJsZW5jb2RlZFBhcnNlciwgYXN5bmMgKHJlcSwgcmVzKSA9PiB7CiAgICBpZihyZXEuYm9keS5oYXNPd25Qcm9wZXJ0eSgia2V5d29yZCIpJiZyZXEuYm9keS5oYXNPd25Qcm9wZXJ0eSgibWVzc2FnZSIpKXsKCSAgICBsZXQgZXJyb3I9YXdhaXQgcG9zdE1lc3NhZ2UocmVxLmJvZHkua2V5d29yZCxyZXEuYm9keS5tZXNzYWdlKTsKICAgICAgICByZXMuc2VuZCh7cmVzdWx0OiJIZXksIHRoYXQgd29ya2VkISIsZXJyb3J9KTsKICAgIH0KICAgIGVsc2V7CiAgICAgICAgcmVzLnNlbmQoe2Vycm9yOiJSZXF1ZXN0IG11c3QgaW5jbHVkZSBhIGtleXdvcmQgYW5kIGEgbWVzc2FnZS4ifSk7CiAgICB9Cn0pOwoKYXBwLmxpc3RlbigzMDAwLCAoKSA9PiBjb25zb2xlLmxvZygnc2VydmVyIHN0YXJ0ZWQnKSk7"},"asBuffer":null},"loaded":true}}
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'));