Skip to content

Instantly share code, notes, and snippets.

@sunho
Created May 22, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunho/1bdc070f3b20353700a507c446c57d97 to your computer and use it in GitHub Desktop.
Save sunho/1bdc070f3b20353700a507c446c57d97 to your computer and use it in GitHub Desktop.
fetch("http://localhost:5353/10", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"game": {"hello":"hi"}})
});
fetch("http://localhost:5353/10").then(x => x.json()).then(x => {
console.log(x);
});
const express = require('express');
const bodyParser = require("body-parser");
const cors = require('cors');
const app = express();
let games = {};
app.use(bodyParser());
app.use(cors());
app.options('/:id', cors());
app.get('/:id', (req, res) => {
const game = games[req.param('id')];
if (game) {
res.json(game);
} else {
res.sendStatus(404);
}
});
app.post('/:id', (req, res) => {
games[req.param('id')] = req.body['game'];
res.sendStatus(200);
});
app.listen(5353);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment