This short post shows how to get a self-executable Deno HTTP server to run in Nanos using Ops.
The server
const port = Number(Deno.env.get('PORT'));
const listener = Deno.listen({ port: port });
console.log(`http://localhost:${port}`);
for await (const conn of listener) {
(async () => {
const requests = Deno.serveHttp(conn);
for await (const { respondWith } of requests) {
respondWith(new Response("Hello world"));
}
})();
}
Compilation and local deployment
deno compile --allow-env --allow-net hello.ts
ops run -e HOME=/ -e PORT=8000 -p 8000 hello
The trick is to set the HOME variable. It can have any value, but /
feels right.
Summary
In this post, we have seen a minimal Deno HTTP server working in a Nanos unikernel.
Top comments (0)