Last active
August 17, 2018 06:22
-
-
Save drwpow/ec9316bb554f3130135c636f71cf56c2 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 Koa = require('koa'); | |
const serve = require('koa-static'); | |
const { get } = require('koa-route'); | |
const app = new Koa(); | |
app.use( | |
get('/api/v1/peaks', ctx => { | |
const data = require('./data/summits.json'); | |
ctx.body = data; | |
}) | |
); | |
app.use(serve('src/public')); | |
app.listen(3000); |
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 Koa = require('koa'); | |
const serve = require('koa-static'); | |
const { get } = require('koa-route'); | |
// Note: you can use brackets as a shortcut… instead of _.get(), { get } is quicker. | |
// Good to save space / if you only need one thing; otherwise, importing all may be quicker. | |
const app = new Koa(); | |
app.use(serve('src/public')); | |
// JSON endpoint, adapted from https://github.com/koajs/route | |
get('/api/v1/peaks', ctx => { | |
const data = require('../src/data/summits.json') // maybe this should be in server/ innstead? | |
ctx.body = data; | |
// Does this work? | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment