feat(11): adding reverse proxy to module

This commit is contained in:
efim 2023-06-27 15:26:43 +00:00
parent e618397eb8
commit e23afdab6f
1 changed files with 29 additions and 13 deletions

View File

@ -43,6 +43,12 @@ let
default = "localhost";
description = "Host to bind to.";
};
useNginx = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to use Nginx to proxy requests.";
};
};
config = lib.mkIf cfg.enable {
users.groups.price-grid-app-group = { };
@ -51,7 +57,9 @@ let
group = "price-grid-app-group";
};
systemd.services.price-grid-app = {
systemd.services.price-grid-app =
let serverHost = if cfg.useNginx then "localhost" else cfg.host;
in {
description = "My Java Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
@ -59,13 +67,21 @@ let
startLimitBurst = 10;
serviceConfig = {
ExecStart =
"${pkgs.jdk}/bin/java -jar ${package}/bin/priceGridApp.jar -p ${toString cfg.port} --host ${cfg.host}";
"${pkgs.jdk}/bin/java -jar ${package}/bin/priceGridApp.jar -p ${
toString cfg.port
} --host ${serverHost}";
WorkingDirectory = "${package}/bin";
Restart = "on-failure";
User = "price-grid-app-user";
Group = "price-grid-app-group";
};
};
services.nginx = lib.mkIf cfg.useNginx {
virtualHosts.${cfg.host} = {
locations."/".proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
};
};
in {