Skip to content

Instantly share code, notes, and snippets.

@de314
Created April 25, 2019 16:59
Show Gist options
  • Save de314/f2cfd3acfb22f6b5e4eab46cc1265ee3 to your computer and use it in GitHub Desktop.
Save de314/f2cfd3acfb22f6b5e4eab46cc1265ee3 to your computer and use it in GitHub Desktop.
const express = require("@runkit/runkit/express-endpoint/1.0.0");
const jsonServer = require('json-server')
const axios = require('axios')
const app = express(exports);
async function addDataSource(data, url) {
const res = await axios.get(url);
Object.assign(data, res.data)
}
async function initJsonServer() {
const data = {};
await addDataSource(data, 'https://raw.githubusercontent.com/typicode/jsonplaceholder/master/data.json');
const router = jsonServer.router(data)
const middlewares = jsonServer.defaults()
app.use(middlewares)
app.use(router)
}
console.log('v0.1.0')
initJsonServer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment