ivandpf
ivandpf•10mo ago

HTTPS Oak Deno

I want to run Deno Oak over Https in local. I use OpenSsl to create cert and key. But no works.
No description
4 Replies
Deno AI Helper
Deno AI Helper•10mo ago
To run an Oak server over HTTPS in Deno, you'll need to use the listenTls function provided by Deno to create a secure server. The documentation indicates that you can now pass the certificate and private key directly as strings to Deno.listenTls(), which is a more flexible approach than using file paths. Here's a step-by-step guide based on the documentation: 1. Ensure you have your certificate (localhost.crt) and private key (localhost.key) ready. You mentioned you've created these using OpenSSL, which is the correct approach. 2. Read your certificate and key files into strings using Deno.readTextFile. This is an asynchronous operation, so you'll need to await the results. 3. Use these strings to create a TLS listener with Deno.listenTls. Here's an example code snippet from the documentation that demonstrates how to do this:
import { Application } from "https://deno.land/x/oak/mod.ts";

const app = new Application();

// Add your Oak middleware and routes here

const cert = await Deno.readTextFile("path/to/localhost.crt");
const key = await Deno.readTextFile("path/to/localhost.key");

const listener = Deno.listenTls({
hostname: "localhost",
port: 443, // Standard HTTPS port
cert,
key,
});

for await (const conn of listener) {
app.handle(conn);
}
import { Application } from "https://deno.land/x/oak/mod.ts";

const app = new Application();

// Add your Oak middleware and routes here

const cert = await Deno.readTextFile("path/to/localhost.crt");
const key = await Deno.readTextFile("path/to/localhost.key");

const listener = Deno.listenTls({
hostname: "localhost",
port: 443, // Standard HTTPS port
cert,
key,
});

for await (const conn of listener) {
app.handle(conn);
}
Make sure to replace "path/to/localhost.crt" and "path/to/localhost.key" with the actual paths to your certificate and key files. If you're still encountering issues, ensure that: - The certificate and key are correctly formatted and match each other. - The paths to the certificate and key files are correct. - You have the necessary permissions to read the certificate and key files. If you've followed these steps and are still facing problems, please provide more details
Deno AI Helper
Deno AI Helper•10mo ago
about the error messages or issues you're encountering, and I'll do my best to assist you further. 🦕
ivandpf
ivandpfOP•10mo ago
No description
ivandpf
ivandpfOP•10mo ago
... I want a person not a bot I create with mkcert now and no validate certificate