Skip to content

Instantly share code, notes, and snippets.

@CarterLi CarterLi/http.js
Last active Jun 14, 2018

Embed
What would you like to do?
function foo(req, res) {
req.log("hello from foo() handler");
return "foo";
}
function summary(req, res) {
var a, s, h;
s = "JS summary\n\n";
s += "Method: " + req.method + "\n";
s += "HTTP version: " + req.httpVersion + "\n";
s += "Host: " + req.headers.host + "\n";
s += "Remote Address: " + req.remoteAddress + "\n";
s += "URI: " + req.uri + "\n";
s += "Headers:\n";
for (h in req.headers) {
s += " header '" + h + "' is '" + req.headers[h] + "'\n";
}
s += "Args:\n";
for (a in req.args) {
s += " arg '" + a + "' is '" + req.args[a] + "'\n";
}
return s;
}
function baz(req, res) {
res.headers.foo = 1234;
res.status = 200;
res.contentType = "text/plain; charset=utf-8";
res.contentLength = 15;
res.sendHeader();
res.send("nginx");
res.send("java");
res.send("script");
res.finish();
}
worker_processes auto;
events {
worker_connections 1024;
}
http {
js_include http.js;
js_set $foo foo;
js_set $summary summary;
server {
listen 7000;
location / {
add_header X-Foo $foo;
js_content baz;
}
location /summary {
return 200 $summary;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.