Skip to content

Instantly share code, notes, and snippets.

@garcia556
Last active November 22, 2017 18:14
Show Gist options
  • Save garcia556/54cc38b02a33ad9a1720255b6e9bc2dc to your computer and use it in GitHub Desktop.
Save garcia556/54cc38b02a33ad9a1720255b6e9bc2dc to your computer and use it in GitHub Desktop.
Trying to reproduce immutable empty query object for issue #1045
'use strict';
// to be run with node@7.10 and koa@2.3.0
// docker node@7.1.0 image can be build using: https://raw.githubusercontent.com/nodejs/docker-node/b502aa016335c81a586b430328d8fee4897ee440/7.10/alpine/Dockerfile
const
http = require("http"),
Koa = require("koa"),
app = new Koa(),
PORT = 12345,
URL = `http://localhost:${PORT}`;
app.use(ctx => {
console.log(ctx.query)
if (!ctx.query.sort)
ctx.query.sort = "-createdAt"
console.log(ctx.query)
ctx.body = "Hello Koa";
});
app.listen(PORT);
http.get(URL, res => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
console.log(body);
process.exit(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment