Base configuration

The basic configuration of Express Sweet is defined in the config/config.js file.
Click here to download a sample ESM configuration and
here to download a sample CJS configuration.
Explanation of Values
Name Config Description
env_path: string The path to the environment configuration file (.env).
When you start the Express Sweet application, the contents of the environment configuration file are automatically read and saved in process.env.
The default is .env.
cors_enabled: boolean Set to true to allow requests from another domain to the application.
The default is false.
max_body_size: string|number Controls the maximum request body size.
If this is a number, then the value specifies the number of bytes.
if it is a string, the value is passed to the bytes library for parsing.
The default is 100kb.
router_dir: string The directory path where the routes module is located.
The default is the routes directory directly under the application root.
default_router: string Express Sweet can be told to load a default router when a URI is not present, as will be the case when root URL (/) is requested.
For example, to specify a default route, set default_router as follows.
Where blog is the name of the router module you want used.
Next, create the routes/blog.js module.

In the following example, requesting the root URL (/) will result in "Hello World".
import {Router} from 'express';
const router = Router();

router.get('/', (req, res) => {
  res.send('Hello World');
});
export default router;
const express = require('express');
const router = express.Router();

router.get('/', (req, res) => {
  res.send('Hello World');
});
module.exports = router;
rewrite_base_url: (baseUrl: string) => string This is a hook that rewrites the base URL.
If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL.
The default value is the referrer's origin (eg https://example.com).
In this example, https://example.com/admin is used as the base URL.
rewrite_base_url: baseUrl => {
  return `${baseUrl}/admin`;
}
is_ajax: (req: express.Request) => boolean How to determine if it is an ajax request.
The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.

For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
is_ajax: req => {
  // If the request URL begins with /api, it is assumed to be Ajax.
  return /^\/api/.test(req.path);
  // return !!req.xhr;
}
hook_handle_error: (err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void Hooks the default behavior on request errors.
If unset, simply returns an error HTTP status. (res.status(err.status||500).end();)
hook_handle_error: (err, req, res, next) => {
  if (err.status === 404)
    // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
    res.render('error-404');
  else
    // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
    res.render('error-unknown');
},