mirror of
https://github.com/Lissy93/web-check.git
synced 2025-05-18 21:20:45 +02:00
Renders error page, if there was an error
This commit is contained in:
parent
c2a937ac8e
commit
d26f5b26a7
26
server.js
26
server.js
@ -11,6 +11,7 @@ const port = process.env.PORT || 3000; // The port to run the server on
|
|||||||
const API_DIR = '/api'; // Name of the dir containing the lambda functions
|
const API_DIR = '/api'; // Name of the dir containing the lambda functions
|
||||||
const dirPath = path.join(__dirname, API_DIR); // Path to the lambda functions dir
|
const dirPath = path.join(__dirname, API_DIR); // Path to the lambda functions dir
|
||||||
const guiPath = path.join(__dirname, 'build');
|
const guiPath = path.join(__dirname, 'build');
|
||||||
|
const placeholderFilePath = path.join(__dirname, 'public', 'placeholder.html');
|
||||||
const handlers = {}; // Will store list of API endpoints
|
const handlers = {}; // Will store list of API endpoints
|
||||||
process.env.WC_SERVER = 'true'; // Tells middleware to return in non-lambda mode
|
process.env.WC_SERVER = 'true'; // Tells middleware to return in non-lambda mode
|
||||||
|
|
||||||
@ -95,23 +96,34 @@ app.use(historyApiFallback({
|
|||||||
|
|
||||||
// Serve up the GUI - if build dir exists, and GUI feature enabled
|
// Serve up the GUI - if build dir exists, and GUI feature enabled
|
||||||
if (process.env.DISABLE_GUI && process.env.DISABLE_GUI !== 'false') {
|
if (process.env.DISABLE_GUI && process.env.DISABLE_GUI !== 'false') {
|
||||||
app.get('*', (req, res) => {
|
app.get('*', async (req, res) => {
|
||||||
res.status(500).send(
|
const placeholderContent = await fs.promises.readFile(placeholderFilePath, 'utf-8');
|
||||||
'Welcome to Web-Check!<br />Access the API endpoints at '
|
const htmlContent = placeholderContent.replace(
|
||||||
|
'<!-- CONTENT -->',
|
||||||
|
'Web-Check API is up and running!<br />Access the endpoints at '
|
||||||
+'<a href="/api"><code>/api</code></a>'
|
+'<a href="/api"><code>/api</code></a>'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res.status(500).send(htmlContent);
|
||||||
});
|
});
|
||||||
} else if (!fs.existsSync(guiPath)) {
|
} else if (!fs.existsSync(guiPath)) {
|
||||||
app.get('*', (req, res) => {
|
app.get('*', async (req, res) => {
|
||||||
res.status(500).send(
|
const placeholderContent = await fs.promises.readFile(placeholderFilePath, 'utf-8');
|
||||||
'Welcome to Web-Check!<br />Looks like the GUI app has not yet been compiled, '
|
const htmlContent = placeholderContent.replace(
|
||||||
+'run <code>yarn build</code> to continue, then restart the server.'
|
'<!-- CONTENT -->',
|
||||||
|
'Looks like the GUI app has not yet been compiled.<br /> ' +
|
||||||
|
'Run <code>yarn build</code> to continue, then restart the server.'
|
||||||
);
|
);
|
||||||
|
res.status(500).send(htmlContent);
|
||||||
});
|
});
|
||||||
} else { // GUI enabled, and build files present, let's go!!
|
} else { // GUI enabled, and build files present, let's go!!
|
||||||
app.use(express.static(guiPath));
|
app.use(express.static(guiPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.status(404).sendFile(path.join(__dirname, 'public', 'error.html'));
|
||||||
|
});
|
||||||
|
|
||||||
// Print nice welcome message to user
|
// Print nice welcome message to user
|
||||||
const printMessage = () => {
|
const printMessage = () => {
|
||||||
console.log(
|
console.log(
|
||||||
|
Loading…
Reference in New Issue
Block a user