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