Skip to content

Commit

Permalink
Fix to Readdirp handling after migration to v.4.0
Browse files Browse the repository at this point in the history
Fix to Readdirp handling after migration to v4.0:
- let {readdirp} = require('readdirp');
- var localfiles = await new Promise((resolve, reject) => {  ... }
Workflows added

Signed-off-by: Milosz Linkiewicz <[email protected]>
  • Loading branch information
Mionsz committed Sep 24, 2024
1 parent ebc001a commit 72e5725
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
11 changes: 9 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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){
Expand Down
11 changes: 0 additions & 11 deletions root/defaults/default
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 15 additions & 9 deletions root/init.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down

0 comments on commit 72e5725

Please sign in to comment.