From 12aeaa5f956d1c66f16e8092998f14bf64c045b6 Mon Sep 17 00:00:00 2001 From: 4censord Date: Sat, 3 Aug 2024 17:42:59 +0200 Subject: [PATCH 1/2] Complain if no config-files are loaded --- package.json | 2 +- packages/backend/src/config.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 519a8c453d..f60fd789db 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "build": "pnpm build-pre && pnpm -r build && pnpm build-assets", "build-storybook": "pnpm --filter frontend build-storybook", "build-misskey-js-with-types": "pnpm build-pre && pnpm --filter backend... --filter=!misskey-js build && pnpm --filter backend generate-api-json && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && pnpm --filter misskey-js update-autogen-code && pnpm --filter misskey-js build && pnpm --filter misskey-js api", - "start": "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js", + "start": "pnpm check:connect && cd packages/backend && MK_WARNED_ABOUT_CONFIG=true node ./built/boot/entry.js", "start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js", "init": "pnpm migrate", "migrate": "cd packages/backend && pnpm migrate", diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 92774328cc..15fc6fff28 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -222,8 +222,15 @@ export function loadConfig(): Config { JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_vite_/manifest.json`, 'utf-8')) : { 'src/_boot_.ts': { file: 'src/_boot_.ts' } }; - const config = globSync(path).sort() - .map(path => fs.readFileSync(path, 'utf-8')) + const configFiles = globSync(path).sort(); + + if (configFiles.length === 0 + && !process.env['MK_WARNED_ABOUT_CONFIG']) { + console.log('No config files loaded, check if this is intentional'); + process.env['MK_WARNED_ABOUT_CONFIG'] = true; + } + + const config = configFiles.map(path => fs.readFileSync(path, 'utf-8')) .map(contents => yaml.load(contents) as Source) .reduce( (acc: Source, cur: Source) => Object.assign(acc, cur), From e1b0faa18f3b6d7b365f5fc10caaecd6e480644d Mon Sep 17 00:00:00 2001 From: 4censord Date: Sat, 3 Aug 2024 15:21:44 +0200 Subject: [PATCH 2/2] Fall back to port 3000 if none is specified Originally, because `parseInt` can return `NaN`, sharkey would happily try to listen on port `NaN`. --- packages/backend/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 15fc6fff28..44b0a05f24 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -256,7 +256,7 @@ export function loadConfig(): Config { version, publishTarballInsteadOfProvideRepositoryUrl: !!config.publishTarballInsteadOfProvideRepositoryUrl, url: url.origin, - port: config.port ?? parseInt(process.env.PORT ?? '', 10), + port: config.port ?? parseInt(process.env.PORT ?? '3000', 10), socket: config.socket, chmodSocket: config.chmodSocket, disableHsts: config.disableHsts,