From 4deb359af8b73c8d8f53fe5a71ad65baf7f9bca9 Mon Sep 17 00:00:00 2001 From: Cris Stringfellow <22254235+crislin2046@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:50:31 +0800 Subject: [PATCH] Path root works --- src/archivist.js | 2 +- src/common.js | 3 ++- src/libraryServer.js | 7 ++++++- src/root.cjs | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/root.cjs diff --git a/src/archivist.js b/src/archivist.js index 7741b76..2980616 100644 --- a/src/archivist.js +++ b/src/archivist.js @@ -211,8 +211,8 @@ async function collect({chrome_port:port, mode} = {}) { const {library_path} = args; const exitHandlers = []; - process.on('SIGUSR2', runHandlers); process.on('beforeExit', runHandlers); + process.on('SIGUSR2', code => runHandlers(code, 'SIGUSR2', {exit: true})); process.on('exit', code => runHandlers(code, 'exit', {exit: true})); State.connection = State.connection || await connect({port}); State.onExit = { diff --git a/src/common.js b/src/common.js index f680f4c..45df292 100644 --- a/src/common.js +++ b/src/common.js @@ -2,6 +2,7 @@ import path from 'path'; import {fileURLToPath} from 'url'; import fs from 'fs'; import os from 'os'; +import root from './root.cjs'; const DEEB = false; @@ -75,7 +76,7 @@ export const SNIP_CONTEXT = 31; export const NO_SANDBOX = (process.env.DEBUG_22120 && process.env.SET_22120_NO_SANDBOX) || false; //export const APP_ROOT = '.'; -export const APP_ROOT = path.dirname(process.argv[0]); +export const APP_ROOT = root.APP_ROOT; //export const APP_ROOT = path.dirname(fileURLToPath(import.meta.url)); export const sleep = ms => new Promise(res => setTimeout(res, ms)); diff --git a/src/libraryServer.js b/src/libraryServer.js index 4a5fb8b..a11523f 100644 --- a/src/libraryServer.js +++ b/src/libraryServer.js @@ -68,7 +68,12 @@ async function start({server_port}) { throw err; } upAt = new Date; - say({server_up:{upAt,port}}); + say({server_up:{upAt,port, + ...(DEBUG.verboseSlow ? { + static_site_path: SITE_PATH, + app_root: APP_ROOT, + } : {}) + }}); }); } catch(e) { running = false; diff --git a/src/root.cjs b/src/root.cjs new file mode 100644 index 0000000..44a03a9 --- /dev/null +++ b/src/root.cjs @@ -0,0 +1,14 @@ +const path = require('path'); +const url = require('url'); + +const file = __filename; +const dir = path.dirname(file); + +console.log({file, dir}); + +module.exports = { + APP_ROOT: dir, + dir, + file +} +