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