Created
May 22, 2020 16:45
-
-
Save sunho/1bdc070f3b20353700a507c446c57d97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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