Skip to content

Commit

Permalink
[WIP] NGINX JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
agebhar1 committed Jun 16, 2024
1 parent f1bc7ff commit 5ba5201
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
10 changes: 10 additions & 0 deletions container/nginx/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
services:
nginx:
image: docker.io/library/nginx:1.26.1-alpine3.19
ports:
- "8080:80"
volumes:
- ./etc/nginx/conf.d:/etc/nginx/conf.d:ro
- ./etc/nginx/njs:/etc/nginx/njs:ro
- ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
24 changes: 24 additions & 0 deletions container/nginx/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

js_import utils.js;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

location = /njs {
js_content utils.njsInfo;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

}
33 changes: 33 additions & 0 deletions container/nginx/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

load_module modules/ngx_http_js_module.so;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

js_path "/etc/nginx/njs/";

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}
6 changes: 6 additions & 0 deletions container/nginx/etc/nginx/njs/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function njsInfo(r) {
r.headersOut['content-type'] = 'text/javascript';
r.return(200, JSON.stringify(njs))
}

export default {njsInfo}

0 comments on commit 5ba5201

Please sign in to comment.