Created
April 25, 2019 16:59
-
-
Save de314/f2cfd3acfb22f6b5e4eab46cc1265ee3 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
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