Created
March 24, 2015 02:37
-
-
Save kudos/610266fd195b73932dd9 to your computer and use it in GitHub Desktop.
Wrapping Fetchr middleware to make it consumable with Koa
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
"use strict"; | |
const koa = require('koa'); | |
const bodyparser = require('koa-bodyparser'); | |
const koaFetchr = require('koa-fetchr'); | |
const fetchr = require('fetchr'); | |
const app = koa(); | |
app.use(bodyparser()); | |
app.use(koaFetchr(fetchr)); | |
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
"use strict"; | |
module.exports = function (fetchr) { | |
return function* (next) { | |
const mw = fetchr.middleware(); | |
this.req.path = this.req.url; | |
mw(this.req, this.res); | |
return yield* next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment