diff --git a/app.js b/app.js index b528b02..dfb90c7 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,7 @@ var http = require('http').Server(app); var io = require('socket.io')(http, {path: baseurl + 'socket.io'}); var isBinaryFile = require("isbinaryfile").isBinaryFile; var path = require('path'); -var readdirp = require('readdirp'); +let {readdirp} = require('readdirp'); var fetch = require('node-fetch'); var si = require('systeminformation'); const util = require('util'); @@ -182,7 +182,14 @@ io.on('connection', function(socket){ var remotemenuversion = fs.readFileSync('/config/menuversion.txt', 'utf8'); var endpointsfile = fs.readFileSync('/config/endpoints.yml'); var endpoints = yaml.load(endpointsfile); - var localfiles = await readdirp.promise('/assets/.'); + // Wrap readdirp in a promise + var localfiles = await new Promise((resolve, reject) => { + const entries = []; + readdirp('/assets/.') + .on('data', (entry) => entries.push(entry)) + .on('end', () => resolve(entries)) + .on('error', (error) => reject(error)); + }); var assets = []; if (localfiles.length != 0){ for (var i in localfiles){ diff --git a/root/defaults/default b/root/defaults/default index f570074..856eb42 100644 --- a/root/defaults/default +++ b/root/defaults/default @@ -2,17 +2,6 @@ server { listen ${NGINX_PORT}; location / { root /assets; - try_files $uri $uri/ @github; autoindex on; } - - location @github { - rewrite ^ /netbootxyz$uri break; - - proxy_buffer_size 128k; - proxy_buffers 4 256k; - proxy_busy_buffers_size 256k; - - proxy_pass https://github.com; - } } diff --git a/root/init.sh b/root/init.sh index 213b577..d778f6d 100755 --- a/root/init.sh +++ b/root/init.sh @@ -1,23 +1,29 @@ #!/bin/bash set -exo pipefail +SCRIPT_DIR="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")" -# make our folders -mkdir -p /assets /config/nginx/site-confs \ - /config/log/nginx /run /var/lib/nginx/tmp/client_body /var/tmp/nginx +# Leave empty for standard flow or any other value for config recreate. +RECREATE_CONFIGURATION="${RECREATE_CONFIGURATION:-''}" + +# make config, logs, nginx etc. dirs +mkdir -p /var/lib/nginx/tmp/client_body /var/tmp/nginx \ + /config/menus/remote /config/menus/local \ + /config/nginx/site-confs /config/log/nginx /assets /run + +# Check for file exisitance, and depending on environment replace/create/nothing +[[ -n "${RECREATE_CONFIGURATION}" ]] && \ + rm -f /config/nginx/nginx.conf /config/nginx/site-confs/* -# copy config files [[ ! -f /config/nginx/nginx.conf ]] && \ - cp /defaults/nginx.conf /config/nginx/nginx.conf + cp /defaults/nginx.conf /config/nginx/nginx.conf + [[ ! -f /config/nginx/site-confs/default ]] && \ - envsubst < /defaults/default > /config/nginx/site-confs/default + envsubst < /defaults/default > /config/nginx/site-confs/default # Ownership chown -R nbxyz:nbxyz /assets /var/lib/nginx /var/log/nginx -# create local logs dir -mkdir -p /config/menus/remote /config/menus/local - # download menus if not found if [[ ! -f /config/menus/remote/menu.ipxe ]]; then echo "[netbootxyz-init] Downloading netboot.xyz at ${MENU_VERSION}"