Zidan
Zidan
DDeno
Created by Zidan on 5/1/2024 in #help
Deno LSP Issue with import maps?
I've been using an import map throughout my project like this: deno.json file at the projects' root that has a map like this:
{
"imports": {
"atlas": "https://deno.land/x/atlas_sdk@v1.1.1/mod.ts",
"handler": "./source/server/handler.js"
}
}
{
"imports": {
"atlas": "https://deno.land/x/atlas_sdk@v1.1.1/mod.ts",
"handler": "./source/server/handler.js"
}
}
and then for example, import the handler.js file like this:
import handler from 'handler';
import handler from 'handler';
Although its still working just fine. I now see a red curly underline under
'handler'
'handler'
or any other file that's being used in the same way. And when I hover over it, it says "Relative import path "handler" not prefixed with / or ./ or ../ deno(import-prefix-missing)". Am I doing something wrong or is it just an LSP bug?
1 replies
DDeno
Created by Zidan on 8/23/2023 in #help
Closing a file
How do I close a file after opening and streaming it? My handler function code is as follows:
return new Promise(
(grant) => {
Deno.open(
asset.path
).then(
(file) => {
grant(
new Response(
file.readable,
{
status: 200,
headers: {
"content-type": asset.type,
"content-length": file.stat.size.toString()
}
}
)
)
}
)
}
);
return new Promise(
(grant) => {
Deno.open(
asset.path
).then(
(file) => {
grant(
new Response(
file.readable,
{
status: 200,
headers: {
"content-type": asset.type,
"content-length": file.stat.size.toString()
}
}
)
)
}
)
}
);
Is there a good way of closing the "file" after returning the "Response" object?
10 replies
DDeno
Created by Zidan on 8/10/2023 in #help
Serving multiple static files to an HTTP request
If a client sends a request for an array of static files names like so.
["component01.js", "component01.css", "component02.js", "component02.css"]
["component01.js", "component01.css", "component02.js", "component02.css"]
Using a Deno.serve server, is it possible to serve all files in response to that one request, instead of having the client request them one by one? Would I need something like HTTP/2 or HTTP/3? And if so, are any of those supported in Deno?
37 replies
DDeno
Created by Zidan on 7/16/2023 in #help
How to serve HTTPS with the Deno.serve() API
I used to start a dev server with TLS like so
const server = Deno.listenTls({
port: 7000,
transport: 'tcp',
hostname: 'localhost',
certFile: './server/ssl/server.crt',
keyFile: './server/ssl/server.key',
alpnProtocols: ['h2', 'http/1.1']
})

const router = async (connection) => {

const httpConnection = Deno.serveHttp(connection)

for await (const event of httpConnection) {

const url = new URL(event.request.url)
const path = url.pathname
const cookie = event.request.headers.get('cookie')

if (path === '/') {
await event.respondWith(
handlers.main({ cookie })
)
}

}
}

for await (const connection of server) {
router(connection)
}
const server = Deno.listenTls({
port: 7000,
transport: 'tcp',
hostname: 'localhost',
certFile: './server/ssl/server.crt',
keyFile: './server/ssl/server.key',
alpnProtocols: ['h2', 'http/1.1']
})

const router = async (connection) => {

const httpConnection = Deno.serveHttp(connection)

for await (const event of httpConnection) {

const url = new URL(event.request.url)
const path = url.pathname
const cookie = event.request.headers.get('cookie')

if (path === '/') {
await event.respondWith(
handlers.main({ cookie })
)
}

}
}

for await (const connection of server) {
router(connection)
}
but can't seem to do so with the Deno.serve() api
const options = {
port: 7000,
hostname: "localhost",
certFile: "./server/ssl/server.crt",
keyFile: "./server/ssl/server.key",
alpnProtocols: ['h2', 'http/1.1']
}

const handler = (req) => { return new Response("what's up") }

Deno.serve(options, handler)
const options = {
port: 7000,
hostname: "localhost",
certFile: "./server/ssl/server.crt",
keyFile: "./server/ssl/server.key",
alpnProtocols: ['h2', 'http/1.1']
}

const handler = (req) => { return new Response("what's up") }

Deno.serve(options, handler)
It seems to me that the cert and key files in the options object are being ignored and i have no idea why. Any help is greatly appreciated.
168 replies
DDeno
Created by Zidan on 10/1/2022 in #help
ReadableStream to JSON
9 replies