Skip to content

Instantly share code, notes, and snippets.

@rankun203
Last active August 31, 2016 03:02
Show Gist options
  • Save rankun203/76f4fe954591425f692168706a83838e to your computer and use it in GitHub Desktop.
Save rankun203/76f4fe954591425f692168706a83838e to your computer and use it in GitHub Desktop.
Echo everything back to the request sender.
# Install Node.js.
curl -L http://git.io/n-install | bash
# Restart the shell or execute shell profile.
# Install dependency.
npm install koa co-body
const koa = require('koa'),
coBody = require('co-body'),
app = koa();
app.use(function *() {
this.body = {
headers: this.headers,
body : ['POST', 'PUT'].indexOf(this.req.method) >= 0 && (yield coBody(this)) || 'Empty',
query : this.query
};
});
app.listen(30000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment