--debug
Massimo Melina committed
Feb 27, 2025 at 16:00 UTC
f608c8b7fe2bd8385f64a193683816f5510891f0
5 files changed
+9
-10
src/config.ts
+2
@@ -216,6 +216,8 @@ Most common configurations:
216
--consoleFile <path>
217
218
For a description of each configuration, please refer to https://rejetto.com/hfs-config
219
+Other options:
220
+ --debug will print extra information
221
`)
222
process.exit(0)
223
})
\ No newline at end of file
src/const.ts
+2
-2
@@ -22,7 +22,7 @@ try {
22
}
23
catch {}
24
25
-export const DEV = process.env.DEV || argv.dev ? 'DEV' : ''
25
+export const DEV = process.env.DEV ? 'DEV' : ''
26
export const ORIGINAL_CWD = process.cwd()
27
export const HFS_STARTED = new Date()
28
const PKG_PATH = join(__dirname, '..', 'package.json')
@@ -40,7 +40,7 @@ export const CONFIG_FILE = 'config.yaml'
40
41
// we want this to be the first stuff to be printed, then we print it in this module, that is executed at the beginning
42
if (DEV) console.clear()
43
-else console.debug = ()=>{}
43
+else if (!argv.debug) console.debug = ()=>{}
44
console.log(`HFS ~ HTTP File Server`)
45
console.log(`© Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt`)
46
console.log('started', formatTimestamp(HFS_STARTED), DEV)
src/listen.ts
+1
-1
@@ -26,7 +26,7 @@ interface ServerExtra { name: string, error?: string, busy?: Promise<string> }
26
let httpSrv: undefined | http.Server & ServerExtra
27
let httpsSrv: undefined | http.Server & ServerExtra
28
29
-const openBrowserAtStart = defineConfig('open_browser_at_start', !DEV)
29
+const openBrowserAtStart = defineConfig('open_browser_at_start', true)
30
31
export const baseUrl = defineConfig(CFG.base_url, '',
32
x => /(?<=\/\/)[^\/]+/.exec(x)?.[0]) // compiled is host only
src/serveGuiFiles.ts
+3
-6
@@ -4,7 +4,7 @@ import Koa from 'koa'
4
import fs from 'fs/promises'
5
import {
6
API_VERSION, MIME_AUTO, FRONTEND_URI, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, HTTP_NOT_FOUND,
7
- PLUGINS_PUB_URI, VERSION, SPECIAL_URI, ICONS_URI
7
+ PLUGINS_PUB_URI, VERSION, SPECIAL_URI, ICONS_URI, DEV
8
} from './const'
9
import { serveFile } from './serveFile'
10
import { getPluginConfigFields, getPluginInfo, mapPlugins, pluginsConfig } from './plugins'
@@ -27,11 +27,8 @@ const splitUploads = defineConfig(CFG.split_uploads, 0)
27
export const logGui = defineConfig(CFG.log_gui, false)
28
_.each(FRONTEND_OPTIONS, (v,k) => defineConfig(k, v)) // define default values
29
30
-// in case of dev env we have our static files within the 'dist' folder'
31
-const DEV_STATIC = process.env.DEV ? 'dist/' : ''
32
-
30
function serveStatic(uri: string): Koa.Middleware {
34
- const folder = uri.slice(2,-1) // we know folder is very similar to uri
31
+ const folder = (DEV ? 'dist/' : '') + uri.slice(2,-1) // we know folder is very similar to uri
32
let cache: Record<string, Promise<string>> = {}
33
customHtml.emitter.on('change', () => cache = {}) // reset cache at every change
34
return async ctx => {
@@ -45,7 +42,7 @@ function serveStatic(uri: string): Koa.Middleware {
42
if (ctx.method !== 'GET')
43
return ctx.status = HTTP_METHOD_NOT_ALLOWED
44
const serveApp = shouldServeApp(ctx)
48
- const fullPath = join(__dirname, '..', DEV_STATIC, folder, serveApp ? '/index.html': ctx.path)
45
+ const fullPath = join(__dirname, '..', folder, serveApp ? '/index.html': ctx.path)
46
const content = await parseFileContent(fullPath,
47
raw => serveApp || !raw.length ? raw : adjustBundlerLinks(ctx, uri, raw) )
48
.catch(() => null)
src/update.ts
+1
-1
@@ -125,7 +125,7 @@ export async function update(tagOrUrl: string='') {
125
const asset = update.assets.find((x: any) => x.name.includes(assetSearch) && x.name.endsWith('.zip'))
126
|| update.assets.find((x: any) => x.name.endsWith(legacyAssetSearch))
127
if (!asset)
128
- throw "asset not found"
128
+ throw `asset not found: ${assetSearch}`
129
url = asset.browser_download_url
130
}
131
if (url) {