Commit ac383f2f authored by Aral Balkan's avatar Aral Balkan
Browse files

Support routes.cjs in addition to route.js

(For advanced routing.)
parent 6d5c1c52
......@@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [16.5.1] - 2021-04-23
### Added
- Support for `routes.cjs` file in addition to `routes.js` file for advanced routing.
## [16.5.0] - 2021-04-23
### Added
- Custom middleware. You can now add any piece of standard Express middleware to your server by defining them as modules in a `.middleware` directory in your project.
- Your routes (and middleware) can now be defined in `.cjs` files in addition to `.js` ones.
## [16.4.1] - 2021-04-17
......
......@@ -876,7 +876,7 @@ In either case, your dynamic routes go into a directory named _.dynamic_ in the
### DotJS
DotJS maps JavaScript modules in a file system hierarchy to routes on your web site in a manner that will be familiar to anyone who has ever used PHP.
DotJS maps JavaScript modules defined in `.js` and `.cjs` files within a file system hierarchy to routes on your web site in a manner that will be familiar to anyone who has ever used PHP.
#### GET-only (simplest approach)
......
......@@ -49,7 +49,6 @@ const asyncForEach = require('./lib/async-foreach')
const errors = require('./lib/errors')
const Util = require('./lib/Util')
class Site {
//
......@@ -1535,17 +1534,20 @@ class Site {
}
//
// Rule 1: Check if a routes.js file exists. If it does, we just need to load that in.
// ===================================================================================
// Rule 1: Check if a routes.js/.cjs file exists. If it does, we just need to load that in.
// ========================================================================================
//
const routesJsFile = path.join(dynamicRoutesDirectory, 'routes.js')
const routesCjsFile = path.join(dynamicRoutesDirectory, 'routes.cjs')
const advancedRoutesFile = fs.existsSync(routesJsFile) ? routesJsFile : fs.existsSync(routesCjsFile) ? routesCjsFile : undefined
if (fs.existsSync(routesJsFile)) {
this.log(' 🐁 ❨site.js❩ Found routes.js file, will load dynamic routes from there.')
if (advancedRoutesFile !== undefined) {
this.log(` 🐁 ❨site.js❩ Found advanced routes file (${advancedRoutesFile}), will load dynamic routes from there.`)
// We flag that this needs to be done here and actually require the file
// once the server has been created so that WebSocket routes can be added also.
this.routesJsFile = routesJsFile
this.routesJsFile = advancedRoutesFile
// Add POST handling in case there are POST routes defined.
addBodyParser()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment