Use environment variables for ports in web app

This commit is contained in:
thiloho
2024-08-10 22:20:57 +02:00
parent 0866e2631d
commit 162118bb56
23 changed files with 347 additions and 223 deletions

View File

@@ -30,13 +30,18 @@
forwardPorts = [
{
from = "host";
host.port = 13000;
guest.port = 3000;
host.port = 5000;
guest.port = 5000;
}
{
from = "host";
host.port = 14000;
guest.port = 4000;
host.port = 10000;
guest.port = 10000;
}
{
from = "host";
host.port = 15000;
guest.port = 15000;
}
];
};
@@ -44,7 +49,7 @@
services.archtika = {
enable = true;
package = localArchtikaPackage;
jwtSecret = "test-secret";
jwtSecret = "a42kVyAhTImYxZeebZkApoAZLmf0VtDA";
};
system.stateVersion = "24.05";

View File

@@ -41,27 +41,33 @@ in
port = mkOption {
type = types.port;
default = 3000;
default = 5000;
description = "Port on which the API runs.";
};
webAppPort = mkOption {
type = types.port;
default = 4000;
default = 10000;
description = "Port on which the web application runs.";
};
nginxPort = mkOption {
type = types.port;
default = 15000;
description = "Port on which NGINX runs.";
};
};
config = mkIf cfg.enable {
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = "/var/lib/archtika";
createHome = true;
};
users.groups.${cfg.group} = { };
systemd.tmpfiles.rules = [ "d /var/www/archtika-websites 0755 ${cfg.user} ${cfg.group} -" ];
systemd.services.archtika-api = {
description = "archtika API service";
wantedBy = [ "multi-user.target" ];
@@ -97,7 +103,7 @@ in
};
script = ''
ORIGIN=http://localhost:${toString cfg.webAppPort} PORT=${toString cfg.webAppPort} ${pkgs.nodejs_22}/bin/node ${cfg.package}/web-app
ORIGIN=http://localhost:${toString cfg.webAppPort} PORT=${toString cfg.webAppPort} ARCHTIKA_API_PORT=${toString cfg.port} ARCHTIKA_NGINX_PORT=${toString cfg.nginxPort} ${pkgs.nodejs_22}/bin/node ${cfg.package}/web-app
'';
};
@@ -120,6 +126,25 @@ in
enable = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts."_" = {
listen = [
{
addr = "0.0.0.0";
port = cfg.nginxPort;
}
];
locations = {
"/" = {
root = "/var/www/archtika-websites";
index = "index.html";
tryFiles = "$uri $uri/ $uri/index.html =404";
extraConfig = ''
autoindex on;
'';
};
};
};
};
};
}