Skip to content

Instantly share code, notes, and snippets.

@drwpow
Last active August 17, 2018 06:22
Show Gist options
  • Save drwpow/ec9316bb554f3130135c636f71cf56c2 to your computer and use it in GitHub Desktop.
Save drwpow/ec9316bb554f3130135c636f71cf56c2 to your computer and use it in GitHub Desktop.
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);
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