From 91824803a18066f5ce933e1cdfa1fe40c3378125 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Mon, 10 Jul 2023 23:09:42 -0600 Subject: [PATCH] feat: startup/routing behavior changes if user conf doesn't exist --- src2/app.ts | 3 ++- src2/routers/index.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src2/app.ts b/src2/app.ts index 5ca5c13..6c8448e 100644 --- a/src2/app.ts +++ b/src2/app.ts @@ -84,7 +84,8 @@ async function main() { app.use('/', (await import('./routers/index')).router); // Host app - app.listen(serverConfig.port, serverConfig.host, () => log.success('Server listening', 'Ready for uploads', `click http://127.0.0.1:${serverConfig.port}`)); + const userConfigExists = await fs.pathExists(path.join('userconfig.json')); + app.listen(serverConfig.port, serverConfig.host, () => log[userConfigExists ? 'success' : 'warn']('Server listening', userConfigExists ? 'Ready for uploads' : 'Setup required', `click http://127.0.0.1:${serverConfig.port}`)); } // Launch log diff --git a/src2/routers/index.ts b/src2/routers/index.ts index 047123f..67c4eb1 100644 --- a/src2/routers/index.ts +++ b/src2/routers/index.ts @@ -1,8 +1,11 @@ +import fs from 'fs-extra'; +import { path } from '@tycrek/joint'; import { Router, json as BodyParserJson } from 'express'; import { log } from '../log'; const router = Router({ caseSensitive: true }); +const userConfigExists = fs.pathExistsSync(path.join('userconfig.json')); -router.get('/', (req, res) => res.render('index')); +router.get('/', (req, res) => userConfigExists ? res.render('index') : res.redirect('/setup')); export { router };