Commit 0e21bd83 authored by Zak Stephens's avatar Zak Stephens

Start implementing world, snapshots.

parent ffb355b8
......@@ -11,11 +11,36 @@ const app = require('express')();
const [playerRepository] = await Promise.all([require('./repositories/player/sqlite')(db)]);
// TODO: Load from file, db, etc.
const world = {
players = []
};
new Proxy(world, {
set:
});
/* Don't start serving until async dependency setup is complete.
* It makes the code easier to reason about. */
app.use('/api/v1/players', require('./routes/players')(playerRepository));
app.use('/api/v1/snapshots', require('./routes/snapshots'));
app.use('/api/v1/players', require('./routes/players')(world, playerRepository));
app.use('/api/v1/snapshots', require('./routes/snapshots')(world));
const options = {
cert: fs.readFileSync(config.get('tls.certFilePath')),
......
module.exports = playerRepository => {
module.exports = (world, playerRepository)=> {
const express = require('express');
const router = express.Router();
......@@ -10,19 +10,16 @@ module.exports = playerRepository => {
playerRepository.createUser(req.body.username, req.body.password)
.then(() => res.sendStatus(201))
.catch(error => {
console.error(error);
res.sendStatus(500);
});
.catch(next);
});
router.post('/:username/movements', (req, res) => {
// TODO
});
return router;
}
};
const router = require('express').Router();
module.exports = world => {
router.get('/', (req, res) => {
const router = require('express').Router();
});
router.get('/:frame?', (req, res) => {
module.exports = router;
/* Time travel! */
let frame = 0;
if (req.params.frame) {
frame = parseInt(req.params.frame);
if (isNaN(frame)) {
return res.sendStatus(400);
}
}
//
});
return router;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment