Base Path refers to the access path prefix for static resources (such as JavaScript, CSS, images, etc.) in an application. In Esmx, proper base path configuration is crucial for the following scenarios:
Esmx adopts an automatic path generation mechanism based on the service name. By default, the framework reads the name field in the project's package.json to generate the base path for static resources: /your-app-name/.
{
"name": "your-app-name"
}This convention-over-configuration design has the following advantages:
name field in package.jsonIn real-world projects, we often need to deploy the same codebase to different environments or regions. Esmx provides support for dynamic base paths, enabling applications to adapt to various deployment scenarios.
- example.com -> Default main site
- example.com/cn/ -> Chinese site
- example.com/en/ -> English site- example.com -> Default main site
- cn.example.com -> Chinese site
- en.example.com -> English siteYou can dynamically set the base path based on the request context through the base parameter of the esmx.render() method:
const render = await esmx.render({
base: '/cn',
params: {
url: req.url
}
});