Commit 7b0ad4f3 authored by Zak Stephens's avatar Zak Stephens

Get half an architecture based on dependency-injection working.

parent 22741ec9
......@@ -4,6 +4,9 @@
# Certificates and certificate accessories
keys/
# SQLite database
db.sqlite3
# Logs
logs
*.log
......
{
"databaseFilePath": "db.sqlite3",
"tls": {
"certFilePath": "keys/local.crt",
"keyFilePath": "keys/local.key"
......
const config = require('config');
const fs = require('fs');
const https = require('https');
/* */
/* */
const sqlite3 = require('sqlite3');
const app = require('express')();
app.use('/api/v1', require('./routes'));
const db = new sqlite3.Database(config.get('databaseFilePath'));
const playerRepository = require('./repositories/player/sqlite')(db);
app.use('/api/v1/players', require('./routes/players')(playerRepository));
app.use('/api/v1/snapshots', require('./routes/snapshots'));
const options = {
cert: fs.readFileSync(config.get('tls.certFilePath')),
......
This diff is collapsed.
......@@ -17,7 +17,8 @@
"homepage": "https://gitlab.com/0xc0c0a/wayfarers-rest-server#readme",
"dependencies": {
"config": "^3.1.0",
"express": "^4.16.4"
"express": "^4.16.4",
"sqlite3": "^4.0.6"
},
"private": true
}
module.exports = db => ({
createPlayer: (username, password) => {
}
});
const router = require('express').Router();
router.use('/players', require('./players'));
router.use('/snapshots', require('./snapshots'));
module.exports = router;
const router = require('express').Router();
module.exports = playerRepository => {
router.post('/', (req, res) => {
// TODO: Create account.
});
const express = require('express');
const router = express.Router();
router.post('/:username/movements', (req, res) => {
// TODO
});
router.post('/', express.json(), (req, res) => {
module.exports = router;
const username = req.body.username;
const password = req.body.password;
if (username === null || password === null) {
return res.sendStatus(400);
}
playerRepository.createPlayer(username, password);
res.sendStatus(201);
});
router.post('/:username/movements', (req, res) => {
// TODO
});
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