Skip to content

Instantly share code, notes, and snippets.

@nginx-gists
Last active November 11, 2022 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nginx-gists/210b6e57bde33ec23099bc92326d2fd0 to your computer and use it in GitHub Desktop.
Save nginx-gists/210b6e57bde33ec23099bc92326d2fd0 to your computer and use it in GitHub Desktop.
Make Your NGINX Config Even More Modular and Reusable with njs 0.7.7
server {
listen 4001;
js_import util from util.mjs;
location /foo {
js_content util.handler;
}
}
# vim: syntax=nginx
server {
listen 4001;
location /foo {
# Where is 'util' defined? It's not obvious in this context
js_content util.handler;
}
}
# vim: syntax=nginx
http {
# util.mjs is not actually invoked in this file
js_import util from util.mjs;
# This reads in jscode_local.conf, where 'util' is actually invoked
include /etc/nginx/conf.d/*.conf;
}
@nginx-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment