Last active
November 22, 2017 18:14
-
-
Save garcia556/54cc38b02a33ad9a1720255b6e9bc2dc to your computer and use it in GitHub Desktop.
Trying to reproduce immutable empty query object for issue #1045
This file contains hidden or 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'; | |
// to be run with [email protected] and [email protected] | |
// docker [email protected] 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