Skip to content

Commit

Permalink
fix: Add error handle to main page
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Feb 28, 2024
1 parent 1d0e4ea commit fd9a0cc
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,39 +313,48 @@ export default function buildBaseApi(app: HttpServer) {
});

app.route(/.*/, 'GET', (req, res) => {
const url = req.pathname || '/';
const folderPath =
config.staticFolderPath || path.join(pkgRunningFolder, 'static');
try {
const url = req.pathname || '/';
const folderPath =
config.staticFolderPath ||
path.join(pkgRunningFolder, 'static');

if (url == '/') {
if (req.query?.tab == '1') {
return buildExternalCounters(res);
}
if (url == '/') {
if (req.query?.tab == '1') {
return buildExternalCounters(res);
}

if (req.query?.tab == '2') {
return buildSettings(res);
}
if (req.query?.tab == '2') {
return buildSettings(res);
}

if (req.query?.tab == '3') {
return buildInstructionLocal(res);
}

if (req.query?.tab == '3') {
return buildInstructionLocal(res);
return buildLocalCounters(res);
}

return buildLocalCounters(res);
}
const extension = path.extname(url);
if (extension == '' && !url.endsWith('/')) {
res.writeHead(301, { Location: url + '/' });
return res.end();
}

const extension = path.extname(url);
if (extension == '' && !url.endsWith('/')) {
res.writeHead(301, { Location: url + '/' });
return res.end();
const selectIndexHTML = url.endsWith('/')
? url + 'index.html'
: url;
directoryWalker({
_htmlRedirect: true,
res,
baseUrl: url,
pathname: selectIndexHTML,
folderPath
});
} catch (error) {
return sendJson(res, {
error: (error as any).message
});
}

const selectIndexHTML = url.endsWith('/') ? url + 'index.html' : url;
directoryWalker({
_htmlRedirect: true,
res,
baseUrl: url,
pathname: selectIndexHTML,
folderPath
});
});
}

0 comments on commit fd9a0cc

Please sign in to comment.