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"; default = "localhost";
description = "Host to bind to."; 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 { config = lib.mkIf cfg.enable {
users.groups.price-grid-app-group = { }; users.groups.price-grid-app-group = { };
@ -51,19 +57,29 @@ let
group = "price-grid-app-group"; group = "price-grid-app-group";
}; };
systemd.services.price-grid-app = { systemd.services.price-grid-app =
description = "My Java Service"; let serverHost = if cfg.useNginx then "localhost" else cfg.host;
wantedBy = [ "multi-user.target" ]; in {
after = [ "network.target" ]; description = "My Java Service";
startLimitIntervalSec = 30; wantedBy = [ "multi-user.target" ];
startLimitBurst = 10; after = [ "network.target" ];
serviceConfig = { startLimitIntervalSec = 30;
ExecStart = startLimitBurst = 10;
"${pkgs.jdk}/bin/java -jar ${package}/bin/priceGridApp.jar -p ${toString cfg.port} --host ${cfg.host}"; serviceConfig = {
WorkingDirectory = "${package}/bin"; ExecStart =
Restart = "on-failure"; "${pkgs.jdk}/bin/java -jar ${package}/bin/priceGridApp.jar -p ${
User = "price-grid-app-user"; toString cfg.port
Group = "price-grid-app-group"; } --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}";
}; };
}; };
}; };