config/mode
When writing some files out locally and wanting to preview everything, it can be a bit annoying having to restart the server every time you've fixed a typo or want to see how it looks. umejs can alleviate the pain a bit! When creating files locally, you can enable development mode.
Warning
It is not recommended to set the mode todevelopmentin production!
Warning
Setting development mode to
truestarts a file watcher. This needs to be closed when you stop the server as well!
Here's en example config of umejs with the mode set to development:
const ume = require("@dantenl/umejs")
const path = require('path');
const umeConfig = ume({
mode: "development",
// "production" is default
// example contentDir and templatePath
contentDir: path.join(__dirname, 'content'),
templatePath: path.join(__dirname, 'layout.ume.html'),
})
// ! IMPORTANT: close the file watcher!
process.on('SIGINT', async () => {
await umeConfig.close();
process.exit(0);
});
The default value is production.
If you wish to, you could also automatically change this with for example your .env file. For this example, the npm module dotenv is used.
// --- Import Express and umejs ---
const ume = require('@dantenl/umejs');
const express = require('express');
const path = require('path');
// --- Add .env ---
require('dotenv').config({ quiet: true})
// --- Initialise Express ---
const app = express();
const PORT = 3000
// --- Set dev mode ---
const DEV_MODE = process.env.DEV_MODE ? "development" : "production"
// if true, set string to "development". if not: "production"
// --- Initialise umejs ---
const umeConfig = ume({
contentDir: path.join(__dirname, 'blog'),
templatePath: path.join(__dirname, 'template', 'layout.ume.html'),
mode: DEV_MODE
});
// --- Set up the umejs middleware ---
app.use('/blog/{*slug}', umeConfig);
// --- Get the server running ---
const server = app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
// --- Close the file watcher ---
process.on('SIGINT', async () => {
server.close();
await middleware.close();
process.exit(0);
});
Your .env file would look like this:
DEV_MODE=true