Skip to content

Instantly share code, notes, and snippets.

@pokorson
Created November 23, 2019 11:28
Show Gist options
  • Save pokorson/2b1f47bb01c2285de1149a42a064651c to your computer and use it in GitHub Desktop.
Save pokorson/2b1f47bb01c2285de1149a42a064651c to your computer and use it in GitHub Desktop.
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 3000;
app.use(cors());
const jsonParser = bodyParser.json();
const users = [];
const messages = [
{ body: 'test message', sentBy: 'test user' }
];
app.post('/login', jsonParser, (req, res) => {
const user = {
login: req.body.login
}
users.push(user);
console.log(`User ${user.login} joined`);
return res.json(user);
})
app.post('/sendMessage', jsonParser, (req, res) => {
const message = {
body: req.body.message,
sentBy: req.body.login
}
messages.push(message);
return res.json(message);
})
app.get('/messages', (req, res) => {
return res.json(messages);
})
app.get('/', (req, res) => res.send("stary tekst"));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment