Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created February 1, 2024 05:23
Show Gist options
  • Save xeioex/f3ceec948833c254dfb51bee4b7e48eb to your computer and use it in GitHub Desktop.
Save xeioex/f3ceec948833c254dfb51bee4b7e48eb to your computer and use it in GitHub Desktop.
error_log /dev/stdout info;
daemon off;
master_process off;
#worker_processes 1;
events { }
http {
js_import main from fetch.js;
resolver 1.1.1.1;
server {
listen 8000;
location / {
js_content main.fetch;
}
}
server {
listen 8001;
location / {
js_content main.reply;
}
}
}
async function fetch(r) {
let reply = await ngx.fetch("http://127.0.0.1:8001/",
{ headers: { 'x-ms': "a", 'foo': 'xxx', 'Content-Length': "0" } })
let body = await reply.text();
r.return(200, body);
}
function reply(r) {
let body = [njs.version, '\n'];
r.rawHeadersIn.forEach((header) => {
body.push(`${header[0]}: ${header[1]}\n`);
});
r.return(200, body.join(''));
}
export default { fetch, reply };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment