D
Deno

help

Deno.serveTls with self signed certificate

CChilliSniff10/1/2022
i try to create a webserver but i cannot use self signed certificates, how can i solve this ?
deno run -A --unsafely-ignore-certificate-errors webserver.js
DANGER: TLS certificate validation is disabled for all hostnames
HTTP webserver running. Access it at: http://localhost:8080/
HTTPS webserver running. Access it at: https://localhost:8443/
TLS alert received: AlertMessagePayload {
level: Fatal,
description: CertificateUnknown,
}
error: Uncaught (in promise) Http: error writing a body to connection: received fatal alert: CertificateUnknown
for await (const o_request_event of o_http_connection) {
deno run -A --unsafely-ignore-certificate-errors webserver.js
DANGER: TLS certificate validation is disabled for all hostnames
HTTP webserver running. Access it at: http://localhost:8080/
HTTPS webserver running. Access it at: https://localhost:8443/
TLS alert received: AlertMessagePayload {
level: Fatal,
description: CertificateUnknown,
}
error: Uncaught (in promise) Http: error writing a body to connection: received fatal alert: CertificateUnknown
for await (const o_request_event of o_http_connection) {
Nnotiggsam10/1/2022
Can you show how you create your server object?
CChilliSniff10/2/2022
// var self = this;
var o_server_https = Deno.listenTls(
{
certFile: o_self.o_config.o_ssl.s_path_certificate_file,
keyFile: o_self.o_config.o_ssl.s_path_key_file,
port: o_self.o_config.o_encrypted.n_port,
hostname: o_self.o_config.o_encrypted.s_host,
}
);

for await (const o_http_connection of o_server_https) {
// In order to not be blocking, we need to handle each o_connectionection individually
// without awaiting the function
// o_self.f_serve_https_or_https(o_connection);
const o_http_connection = Deno.serveHttp(o_connection);
// Each request sent over the HTTP connection will be yielded as an async
// iterator from the HTTP connection.
for await (const o_request_event of o_http_connection) {
// The native HTTP server uses the web standard `Request` and `Response`
// objects.
const body = `Your user-agent is:\n\n${
o_request_event.request.headers.get("user-agent") ?? "Unknown"
}`;
// The o_request_event's `.respondWith()` method is how we send the response
// back to the client.
o_request_event.respondWith(
new Response(body, {
status: 200,
}),
);
}
}

// var self = this;
var o_server_https = Deno.listenTls(
{
certFile: o_self.o_config.o_ssl.s_path_certificate_file,
keyFile: o_self.o_config.o_ssl.s_path_key_file,
port: o_self.o_config.o_encrypted.n_port,
hostname: o_self.o_config.o_encrypted.s_host,
}
);

for await (const o_http_connection of o_server_https) {
// In order to not be blocking, we need to handle each o_connectionection individually
// without awaiting the function
// o_self.f_serve_https_or_https(o_connection);
const o_http_connection = Deno.serveHttp(o_connection);
// Each request sent over the HTTP connection will be yielded as an async
// iterator from the HTTP connection.
for await (const o_request_event of o_http_connection) {
// The native HTTP server uses the web standard `Request` and `Response`
// objects.
const body = `Your user-agent is:\n\n${
o_request_event.request.headers.get("user-agent") ?? "Unknown"
}`;
// The o_request_event's `.respondWith()` method is how we send the response
// back to the client.
o_request_event.respondWith(
new Response(body, {
status: 200,
}),
);
}
}

according to what i read online the flag --unsafely-ignore-certificate-errors should allow self signed certs but i still get this error: error: Uncaught (in promise) Http: error writing a body to connection: received fatal alert: CertificateUnknown ?
UUUnknown User10/2/2022
2 Messages Not Public
Sign In & Join Server To View
CChilliSniff10/2/2022
but if i do the exact same with Deno.listen which does not use a ssl certificate i dont get that error
UUUnknown User10/2/2022
Message Not Public
Sign In & Join Server To View
CChilliSniff10/2/2022
wtf like this it works
var o_server_https = Deno.listenTls(
{
certFile: o_self.o_config.o_ssl.s_path_certificate_file,
keyFile: o_self.o_config.o_ssl.s_path_key_file,
port: o_self.o_config.o_encrypted.n_port,
hostname: o_self.o_config.o_encrypted.s_host,
}
);

while (true) {
try {
const o_connection = await o_server_https.accept();
// ... handle the o_connectionection ...
// console.log(o_connection)
const o_http_connection = Deno.serveHttp(o_connection);
while (true) {
console.log("no connection yet")
try {
const requestEvent = await o_http_connection.nextRequest();
// ... handle requestEvent ...
await requestEvent.respondWith(
new Response("hello world", {
status: 200,
}),
);
} catch (err) {
// the connection has finished
break;
}
}

} catch (err) {
// The listener has closed
break;
}
}
var o_server_https = Deno.listenTls(
{
certFile: o_self.o_config.o_ssl.s_path_certificate_file,
keyFile: o_self.o_config.o_ssl.s_path_key_file,
port: o_self.o_config.o_encrypted.n_port,
hostname: o_self.o_config.o_encrypted.s_host,
}
);

while (true) {
try {
const o_connection = await o_server_https.accept();
// ... handle the o_connectionection ...
// console.log(o_connection)
const o_http_connection = Deno.serveHttp(o_connection);
while (true) {
console.log("no connection yet")
try {
const requestEvent = await o_http_connection.nextRequest();
// ... handle requestEvent ...
await requestEvent.respondWith(
new Response("hello world", {
status: 200,
}),
);
} catch (err) {
// the connection has finished
break;
}
}

} catch (err) {
// The listener has closed
break;
}
}

Looking for more? Join the community!

Recommended Posts
ReadableStream to JSONi cant seem to get a JSON out of the request.body i attached pictures for the front end JS request cdistinguis `netERR_CONNECTION_TIMED_OUT` from `netERR_CERT_AUTHORITY_INVALID`i get `net::ERR_CERT_AUTHORITY_INVALID` because i use self signed certs on the domain `localhost` nCommand doesn't work in deno task but works outside of deno taskThe command in question: ```(find . -name '*.js'; find . -name '*.as') | grep -v bundle | xargs wc -How do I patch a std api?Hello. This person posted in this command that they "patched" the `vm.isContext` function to returnMonkey patch Broadcast Channel to send messages to current contextEssentially what I want to do is be able to connect to `new BroadcastChannel("test_channel");` whichDynamically imported module evaluation is still pendingI'm very confused on the error i put as the title because in my program i'm trying to just import soHow to setup CORS with serve? I get 403 forbidden.I've setup the following headers (OPTIONS response): ``` new Response(null, { status: 204, headeDynamic npm imports don't workHey there. It looks like dynamic imports don't work with `npm` specifiers. For example: ``` await iUnable to make local session persistence with Firebase Auth on Deno FreshHello I'm running a basic app for testing firebase auth. My implementation is as follows: - The finewbie help on deploying first project to denoI asked on deno github and was told to ask on discord: https://github.com/denoland/deno/discussions/How to exclude vendor directory from test coverage?https://deno.land/manual@v1.25.4/testing/coverage Here it says by default it will exclude `test\.(tsHow exactly do import maps work?My import map works but I don't understand how! ```"/": "./src/", "./": "./",``` If I import `/a/b/does not provide an export named... module importdoes anybody know whats going on, when i reload my page only sometimes i get this message : ``` ThWrite to virtual file pathIs it possible to provide virtual file paths so that another package writes a file to a variable in Request.body.getReader() into Uint8Array typed arrayis it possible to convert a `readableStream` into a `Uint8Array` ?serving two static folders and connecting to both with websocketsA lot of the youtube and medium resources available on setting serving static folders, and on settini need a regex that matches, from a double quote to a double quote and has two fullstop between it.i need a regex that matches, from a `"` to a `"` and has two `.` between it for example, `"fjhhdjkdimport a locel module from a webmoduleI have a module that i inport into my local scope and that module should also import a module from mSwitching to forums for helpThe old channel is at #old-help and will be archived in a few days.