Zidan
Zidan
Explore posts from servers
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/[email protected]/mod.ts",
"handler": "./source/server/handler.js"
}
}
{
"imports": {
"atlas": "https://deno.land/x/[email protected]/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
KPCKevin Powell - Community
Created by Zidan on 8/25/2023 in #front-end
SVG not displaying
I have a function that returns an SVG element like so:
const svg = document.createElement(`svg`)
svg.className = `logoField`
svg.setAttributeNS(`http://www.w3.org/2000/svg`, `viewBox`, `0 0 95.65 48`)
svg.innerHTML = `
<path d="M297.83,226l-17.35,40.36a12.61,12.61,0,0,1-11.6,7.64H247.21l4.73-11h12.78a4.94,4.94,0,0,0,4.53-3l9.89-23H263.09l4.72-11Z" transform="translate(-202.17 -226)"></path>
<polygon points="19.92 11 15.95 11 20.68 0 24.65 0 19.92 11"></polygon>
<polygon points="35.09 26.98 22.01 37 44.72 37 39.99 48 0 48 0 47.99 0.4 47.07 4.74 36.98 10.67 32.44 16.64 27.87 25.57 21.03 38.67 11 23.88 11 28.61 0 60.66 0 55.93 11.02 35.09 26.98"></polygon>
`
return svg
const svg = document.createElement(`svg`)
svg.className = `logoField`
svg.setAttributeNS(`http://www.w3.org/2000/svg`, `viewBox`, `0 0 95.65 48`)
svg.innerHTML = `
<path d="M297.83,226l-17.35,40.36a12.61,12.61,0,0,1-11.6,7.64H247.21l4.73-11h12.78a4.94,4.94,0,0,0,4.53-3l9.89-23H263.09l4.72-11Z" transform="translate(-202.17 -226)"></path>
<polygon points="19.92 11 15.95 11 20.68 0 24.65 0 19.92 11"></polygon>
<polygon points="35.09 26.98 22.01 37 44.72 37 39.99 48 0 48 0 47.99 0.4 47.07 4.74 36.98 10.67 32.44 16.64 27.87 25.57 21.03 38.67 11 23.88 11 28.61 0 60.66 0 55.93 11.02 35.09 26.98"></polygon>
`
return svg
That code works fine with the VS code live server. But when I use it in a local dev server, the <path> and <polygon> elements' width and height become 0. this is my CSS code:
.logoField {
position: relative;
fill: rgb(200, 200, 200);
height: 3rem;
margin-bottom: 40px;
}
.logoField {
position: relative;
fill: rgb(200, 200, 200);
height: 3rem;
margin-bottom: 40px;
}
NOTE: in the VS code live server, the SVG element is hardcoded into the HTML, it is not rendered by a JavaScript function, but the SVG element code is identical in both cases. Any idea what could be doing wrong? Thanks in advance.
22 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