it's em!
it's em!
DDeno
Created by it's em! on 3/18/2024 in #help
Drop permissions
I'd like to harden my deno app a bit, but specifying permissions manually gets repetitive. Is there a way for me to run with -A, parse my configs, and then drop all permissions I don't need before loading the rest of the app? Ex. the configuration will contain a database path, so I should keep the r/w permissions for that, but not any other files.
5 replies
DDeno
Created by it's em! on 3/7/2024 in #help
Importing internal modules
I would like to use https://github.com/denoland/deno/blob/main/ext/console/01_console.js in my code, but it can't be directly imported from ext: because i'm writing a normal program and not working on the deno cli itself :P Do i just have to vendor and patch it? I'd really rather not.
5 replies
DDeno
Created by it's em! on 1/29/2024 in #help
How can I flush a stream to a response?
I'm trying to stream a response but it appears that data is only sent after either a newline is written or some buffer is filled. Is there a way to manually flush the buffer? To repro, run this with --allow-net, then observe the difference in behavior between curl http://127.0.0.1:8000/%0a and curl http://127.0.0.1:8000/%20.
const encoder = new TextEncoder();
Deno.serve((req) => {
let interval: number;
let i = 0;
const sep = decodeURIComponent(new URL(req.url).pathname.slice(1))
return new Response(
new ReadableStream({
start(c) {
interval = setInterval(() => c.enqueue(encoder.encode(i++ + sep)), 1000)
},
cancel() {
clearInterval(interval)
}
})
)
})
const encoder = new TextEncoder();
Deno.serve((req) => {
let interval: number;
let i = 0;
const sep = decodeURIComponent(new URL(req.url).pathname.slice(1))
return new Response(
new ReadableStream({
start(c) {
interval = setInterval(() => c.enqueue(encoder.encode(i++ + sep)), 1000)
},
cancel() {
clearInterval(interval)
}
})
)
})
7 replies