D
Deno

help

Looking to deploy Deno Fresh on VPS using port 443

Aataractic6/3/2023
Hello! I have two questions, I used saaskit as a base. However fresh's start function is using serve() and not serveTls(). The problem is I cannot expose on 443 since I can't provide certificate and key as start options. Any advice? Should I write a custom start function? My second question is about continuous deployment: I have setup a gitlab runner on my VPS that handles the process of running on each new commit, but unlike NPM, the deno runtime is "listening" and the pipeline stays in "running" state. Is there any solution to this? Thank you!
NNeTT6/3/2023
You can use a reverse proxy like Nginx to point your 443 to your project port
server {
listen 80;
server_name YOUR_URL_HERE;
location / {
proxy_pass http://localhost:YOUR_PORT;
}
}

server {
listen 443 ssl;
server_name YOUR_URL_HERE;
ssl_certificate /PATH/TO/YOUR/CERT.pem;
ssl_certificate_key /PATH/TO/YOUR/KEY.pem;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://localhost:YOUR_PORT;
}
}
server {
listen 80;
server_name YOUR_URL_HERE;
location / {
proxy_pass http://localhost:YOUR_PORT;
}
}

server {
listen 443 ssl;
server_name YOUR_URL_HERE;
ssl_certificate /PATH/TO/YOUR/CERT.pem;
ssl_certificate_key /PATH/TO/YOUR/KEY.pem;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://localhost:YOUR_PORT;
}
}
config like this should do
Aataractic6/3/2023
Thanks a lot! lemme try... I just stumbled upon your previous post, so I will try to resolve the second problem using a daemon and post the CI/CD script here It worked! Installed nginx, bought a cheap 5 years certificate and added it to the VPS, now my website is accessible using https! <:party_deno:1035517691517218847> I also found a way to fix my CI/CD issues, and I think it can be of general interest
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int print_help(int status) {
printf("usage: ./daemonize <bash command>\n\n");

return status;
}

/**
* @brief Executes a bash command as a background task (daemon)
* @param argc Argument count
* @param argv Argument vector
* @return 0 on success, non-zero on failure
*/
int main(int argc, char** argv) {
int status= 0;

if (argc != 2) {
printf("error: invalid syntax\n");
return print_help(1);
}

status = daemon(1, 0);

if (system(argv[1]) != 0) {
return 1;
}

return status;
}
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int print_help(int status) {
printf("usage: ./daemonize <bash command>\n\n");

return status;
}

/**
* @brief Executes a bash command as a background task (daemon)
* @param argc Argument count
* @param argv Argument vector
* @return 0 on success, non-zero on failure
*/
int main(int argc, char** argv) {
int status= 0;

if (argc != 2) {
printf("error: invalid syntax\n");
return print_help(1);
}

status = daemon(1, 0);

if (system(argv[1]) != 0) {
return 1;
}

return status;
}
I created this simple C program that daemonizes a bash command so it can exit the CI/CD pipeline correctly. just run the following command
./daemonize "deno task start"
./daemonize "deno task start"
Here is my gitlab-ci.yml continuous deployment script
stages: # List of stages for jobs, and their order of execution
- deploy

deploy-job: # This job runs in the deploy stage.
stage: deploy
environment: production
script:
# Install deno
- curl -fsSL https://deno.land/x/install/install.sh | sh
- export DENO_INSTALL="/home/gitlab-runner-user/.deno"
- export PATH="$DENO_INSTALL/bin:$PATH"

# Mandatory for prod
- export DENO_DEPLOYMENT_ID="$(git rev-parse HEAD)"

# Test
- deno fmt
- deno task ok

# Kill previous running instance (kill process "deno" that will cause process "daemonize" to terminate), it may fail if there is no deno process running, this is why we add '|| true'
- killall -r "deno" || true

# Run new instance
- ./daemonize "deno task prod"
stages: # List of stages for jobs, and their order of execution
- deploy

deploy-job: # This job runs in the deploy stage.
stage: deploy
environment: production
script:
# Install deno
- curl -fsSL https://deno.land/x/install/install.sh | sh
- export DENO_INSTALL="/home/gitlab-runner-user/.deno"
- export PATH="$DENO_INSTALL/bin:$PATH"

# Mandatory for prod
- export DENO_DEPLOYMENT_ID="$(git rev-parse HEAD)"

# Test
- deno fmt
- deno task ok

# Kill previous running instance (kill process "deno" that will cause process "daemonize" to terminate), it may fail if there is no deno process running, this is why we add '|| true'
- killall -r "deno" || true

# Run new instance
- ./daemonize "deno task prod"
I hope it can be useful to someone, I'll put this short daemonize program on my gitlab!
NNeTT6/3/2023
yep will definitely be useful I personally just use webhooks for CD
Aataractic6/3/2023
may i ask how do you use webhooks for your cd?
NNeTT6/3/2023
I'm lazy with a lot of stuff so Servers receives a request on push and manually runs git pull and systemctl restart xxx.service
Aataractic6/3/2023
could have done that lol

Looking for more? Join the community!

Recommended Posts
Trying to use Deno.serve() for an https static hostingI was trying to setup an simple hello world response in https on my custom domain."https://esm.sh/mercadopago@1.5.15" Is not workin on deploy"https://esm.sh/mercadopago@1.5.15" Is not workin on deno deploy, any clues? it works on local but Simulating physics collisions across isolatesA bit tangential to Deno, but since Deploy uses v8 isolates, it seems that a multiplayer online gameDeno showing node globalThis errorDeno is showing this error: ```js error: Uncaught ReferenceError: __DENO_NODE_GLOBAL_THIS_0_43_0__ iHow to read Chunked request body?Hello! Is it possible to read a chunked request body using `for await`? It seems to only read up to Deno Fresh (Saaskit base) - Impossible to debug errorWhen I try to access my account by logging in, the web app becomes unusable and I get this errorPossible to deploy the chat example to deno deploy?I would like to try running this demo on deno deploy: https://deno.com/manual@v1.34.0/examples/chat`dnt` incompatible with `addEventListener`?I am using the log/mod.ts module from deno_std and running `dnt` with no special configuration as faSaaskit 0.2.0 - URLPattern errorI followed the README.md but when running `deno task start` this error pops up (image) How can i fiRunning `deno cache` fails often with internal server errors when importingExample message ``` error: Import 'https://deno.land/std@0.175.0/path/_constants.ts' failed: 500 IntHow many Web Platform tests should deno be passing?I wanted to package Deno as RPMs but before I started that, I'm getting very different test results Deno Deploy with Cloudflare ProxyIs it possible to use Cloudflare proxy with Deno deploy website? Cloudflare provides countryCode inDeno event loop and gui applicationHi, I am trying to write custom gtk library in deno using `gtk-rs` and `deno_runtime`. I already havSimple type narrowing/type guard/assertion (?)Is there really no simpler way of doing this _without_ `any` and without external deps? ```ts exporImport is "Not yet initialized?"No idea what this means. First screenshot is error, second screenshot is problematic line, third scHow are deno processes/isolates managed in Deploy?Hi, I'm writing a multiplayer game in Deno and currently all of the game state is kept in module-scoCannot access web server from other network devices when compiledHello. Im kinda new to deno and i just compiled my first bigger project with deno, but when the taskHow to use chrome devtools / inspector with Deno?Hello all! I'd like to profile my game server written in Deno to identify the hot spots. I see thaClear local KV storeHow do I delete/clear the local database?Deno.Command not working for applicationHello. Im trying to start an application using Deno.Command, but it for some reason doesnt work. The