deno-express
deno-express copied to clipboard
Requests get ended before await
When i use .then/.catch/.finaly the request gets closed before it could finish the callback.
Example code:
import * as expressive from "https://raw.githubusercontent.com/NMathar/deno-express/master/mod.ts";
const port = 4000; const app = new expressive.App();
app.get("/test", (req, res) => { fetch("http://httpbin.org/get").then(async (e) => { const json = await e.json(); console.log(json);
res.json(json);
});
});
app.listen(port);
seems like it does work when you put it inside a .use/middleware function
Yes because fetch is also asynchronous so it also needs to be awaited
import * as expressive from "https://raw.githubusercontent.com/NMathar/deno-express/master/mod.ts";
const port = 4000;
const app = new expressive.App();
app.get("/test", async (req, res) => {
await fetch("http://httpbin.org/get").then(async (e) => {
const json = await e.json();
console.log(json);
res.json(json);
});
});
app.listen(port);
This does the trick