Skip to content

Instantly share code, notes, and snippets.

@killmenot
Created December 27, 2018 10:18
Show Gist options
  • Save killmenot/7f7b7171683ef397dc9a2fcbec4d2b32 to your computer and use it in GitHub Desktop.
Save killmenot/7f7b7171683ef397dc9a2fcbec4d2b32 to your computer and use it in GitHub Desktop.
Example of using json-server with EwdRedis adapter with Qewd microservices startup
const low = require('lowdb')
const jsonServer = require('json-server')
const config = require('./startup_config.json');
let app;
let bodyParser;
config.addMiddleware = function(bp, express, q) {
bodyParser = bp;
app = express;
};
function onStarted() {
const documentName = 'temp'
const adapterOptions = {}
const adapter = new EwdRedis(documentName, adapterOptions)
const db = low(adapter)
// TODO: add initial state if needed
db.setState({
posts: [],
comments: []
})
const router = jsonServer.router(db)
const middlewares = jsonServer.defaults()
app.use('/api', router);
}
module.exports = {
config: config,
routes: [],
onStarted: onStarted
};
@tony-shannon
Copy link

L20-23 json data should be set outside this export function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment