Ubuntu Server HTTPS

How can I add https i Ubuntu Server to run Deno API over https? Without using Apache. I run deno compiled file in ./home/user/DenoAPI
L
Leokuma20d ago
const cert = Deno.readTextFileSync("./server.crt");

const key = Deno.readTextFileSync("./server.key");

Deno.serve({ cert, key }, (_req) => new Response("Hello, world"));
const cert = Deno.readTextFileSync("./server.crt");

const key = Deno.readTextFileSync("./server.key");

Deno.serve({ cert, key }, (_req) => new Response("Hello, world"));
I
ivandpf20d ago
I have that but no works:
const options = {
hostname: "0.0.0.0",
port: parseInt(Deno.env.get("PORT")!),
cert: Deno.readTextFileSync("./cert.pem"),
key: Deno.readTextFileSync("./key.pem"),
secure: true
};

await app.listen(options);
const options = {
hostname: "0.0.0.0",
port: parseInt(Deno.env.get("PORT")!),
cert: Deno.readTextFileSync("./cert.pem"),
key: Deno.readTextFileSync("./key.pem"),
secure: true
};

await app.listen(options);
I
ivandpf20d ago
I use ur code too:
No description
I
ivandpf20d ago
No description
I
ivandpf20d ago
No description
L
Leokuma20d ago
do you get that error only when running the compiled executable or running with deno run too?
I
ivandpf20d ago
Compile and run, all
L
Leokuma20d ago
I think localhost will always be labeled as insecure by the browser. Maybe you can somehow configure Certificate Authorities on your machine to work around that but I don't know how to do that or whether that's possible at all Also if you use a self-signed certificate, all browsers will consider it insecure
I
ivandpf20d ago
Fck :c
L
Leokuma20d ago
not only browsers will consider it insecure, but also Deno, Postman, curl and every other tool what you can do is to configure your client to ignore unsafe SSL connections that way you can have a self-signed cert and still use the API normally
I
ivandpf20d ago
I have frontend https but if do http request, browser don't like that.
L
Leokuma20d ago
I see. You can't bypass the browser security. But if you call your API from Deno, then you can bypass it
I
ivandpf20d ago
Deploy? I use local database too. I will upload database in other page.
L
Leokuma20d ago
If you "own" the server (VPS), you could maybe create an endpoint like https://mysite.com/api/api-endpoint and use it to proxy/interface with your unsafe API
I
ivandpf20d ago
hmm, with nginx can't bypass?
L
Leokuma20d ago
so the browser calls your HTTPS frontend URL but in the backend the request is forwarded to the API and then sent back to the browser can't bypass with nginx. You will have the same problem wait... maybe you can by using Nginx as a reverse proxy
I
ivandpf20d ago
And I must move API file to /var/www/ path?
L
Leokuma20d ago
no, you can have it anywhere in Nginx you route requests to the port your API is listening to for example your frontend listens on 80 and your API listens on 8080 when someone requests https://mysite.com/api, Nginx forwards it to port 8080 only requests that go to /api will be forwarded to port 8080
I
ivandpf20d ago
Have u got an example of reverse proxy?
L
Leokuma20d ago
once you install Nginx you will configure it in the file /etc/nginx/sites-enabled/default or something the config is something like this:
server {
location /api/ {
proxy_pass http://localhost:8080/;
}
}
server {
location /api/ {
proxy_pass http://localhost:8080/;
}
}
I
ivandpf20d ago
Can I have 1 machine Nginx reverse proxy and another for api? I supose
L
Leokuma20d ago
I never tried that, but I think it works
I
ivandpf20d ago
👍 I will try, thanks.
L
lucsoft18d ago
yeah you can chain them
I
ivandpf18d ago
Thanks
More Posts
Use Deno as a type checker for a front-end project?Hey. I have a need to increase the speed of typechecking my frontend project. I'm not sure, but it sLogger Structure argsI am implementing a simple access log in Deno Fresh, but I am not quite sure how to use the standardAdd static font files as a fresh pluginHello! I'm creating a component library for Fresh. I'm in the part of setting up the plugin part of Compiling code breaks it (except on Linux)error: [ERR_MODULE_NOT_FOUND] Cannot find module "C:\Users\Eris\AppData\Local\Temp\deno-compile-llm-Interface with unknown amount of keys but all the same typeHow do i create an interface/type that can have unlimited keys but the values are all the same type?How to open a file as blob?Docs for Blob (https://deno.land/api@v1.42.0?s=Blob) say that `File` implements `Blob`. But the docsDeno deploy running my code multiple timesIm hosting a small discord bot on deno deploy but for some reason its firing the events multiple timvalue too large in kv (30kb)I'm getting a value too large error when setting a value in KV (on deploy) even though the value is How to work without a tsconfig.json in VSCode? Getting typescript errors due to React.``` Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compilupdate deno version on Alpineon alpine the version of deno is 1.38.1 https://pkgs.alpinelinux.org/packages?name=deno is there a rDeno blog deployment failureHi all, recently tried to make a new blog post on personal blog, however now the deployment fails (nFresh 1.6 - Deno Deploy - TailwindDeploying my project on deno deploy is not working. Does anyone have the same issue ? I am using taAnalyze dependencies for deno compileIs there a way to analyze the dependencies that is added when running deno compile? My compiled binaHow to install jupyter using deno v1.41.xAccording to the documentation https://docs.deno.com/runtime/manual/tools/jupyter the command shouldHelp with TypeScript namespaces - is this pattern supported?Hi! I am attempting to model some classes in a Namespace for organization purposes. I would expect tfont regenerator for copying restriction purposes on DenoI am developing a web reader PWA primarily for reading CJK character text. If I do not want users examples of Deno+LlamacppAre there examples of Deno and Ollama/Llamacpp setups in typescript? Its should t be hard since itIs there a way to bundle multiple files into one file using `esbuild_deno_loader` and `esbuild`?I'm trying to bundle multiple files in a single folder into one JS file that needs to end up in the Deno.stdin raw map?Does anyone have a map to which key is what raw buffer gotten from `Deno.stdin`? Like i can just seaHave the Deno deploy templates disappeared?Good morning, I can't find https://dash.deno.com/new from the account dashboard panel. Are the templ