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 };