1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "nginx-njs";
3
4 nodes.machine = { config, lib, pkgs, ... }: {
5 services.nginx = {
6 enable = true;
7 additionalModules = [ pkgs.nginxModules.njs ];
8 commonHttpConfig = ''
9 js_import http from ${builtins.toFile "http.js" ''
10 function hello(r) {
11 r.return(200, "Hello world!");
12 }
13 export default {hello};
14 ''};
15 '';
16 virtualHosts."localhost".locations."/".extraConfig = ''
17 js_content http.hello;
18 '';
19 };
20 };
21 testScript = ''
22 machine.wait_for_unit("nginx")
23
24 response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/")
25 assert "Hello world!" == response, f"Expected 'Hello world!', got '{response}'"
26 '';
27})