You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
5
5
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).
6
6
7
+
## [17.0.0] - 2021-04-25
8
+
9
+
### Breaking change
10
+
11
+
- If you have an advanced routes file (routes.js) it is loaded prior to any DotJS routes. Previously, the presence of a advanced routes file meant that routes were only loaded from it and that any DotJS routes, if they existed, were ignored. This change means you can use DotJS in your sites and (instead of or), when you need to, define some of your routes using the full expressiveness of Express routes.
12
+
13
+
Although this is a breaking change in that it changes behaviour, the practical impact on existing sites should be minimal given that a project that was using advanced routing would not have had DotJS routes. The only place where this might impact you is if you forgot to delete some old DotJS routes and get surprised when they’re added to your application.
14
+
15
+
### Added
16
+
17
+
- In advanced routes (in routes.js) you now have access to the Site.js class (`app.Site`) and Site.js instance (`app.site`) through the Express `app` instance.
18
+
19
+
- In the statistics view, any routes that begin with _/admin/…_ are shown as ‘Administration page’ to hide any cryptographically-secure paths that may be used as per convention.
Copy file name to clipboardExpand all lines: README.md
+36-4Lines changed: 36 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1389,6 +1389,8 @@ module.exports = app => {
1389
1389
1390
1390
When using the _routes.js_ file, you can use all of the features in [express](https://expressjs.com/) and [our fork of express-ws](https://github.com/aral/express-ws) (which itself wraps [ws](https://github.com/websockets/ws#usage-examples)).
1391
1391
1392
+
__As of Site.js 17.0.0,__ you can also use DotJS routes alongside your advanced routes file. The routes in the _routes.js_ file are loaded first (see [Routing precedence](#routing-precedence), below).
1393
+
1392
1394
### Routing precedence
1393
1395
1394
1396
#### Between dynamic route and static route
@@ -1420,19 +1422,19 @@ The behaviour observed under Linux at the time of writing is that _fun/index.js_
1420
1422
1421
1423
#### Between the various routing methods
1422
1424
1423
-
Each of the routing conventions are mutually exclusive and applied according to the following precedence rules:
1425
+
Each of the routing conventions – apart from advanced _routes.js_-based routing (as of Site.js version 17.0.0) – are mutually exclusive and applied according to the following precedence rules:
1424
1426
1425
-
1. Advanced _routes.js_-based advanced routing.
1427
+
1. Advanced _routes.js_-based routing.
1426
1428
1427
1429
2. DotJS with separate folders for _.https_ and _.wss_ routes routing (the _.http_ folder itself will apply precedence rules 3 and 4 internally).
1428
1430
1429
1431
3. DotJS with separate folders for_.get_ and _.post_ routesin HTTPS-only routing.
1430
1432
1431
1433
4. DotJS with GET-only routing.
1432
1434
1433
-
So, ifSite.js finds a _routes.js_ file in the root folder of your site’s folder, it will only use the routes from that file (it will not apply file-based routing).
1435
+
If Site.js finds a _routes.js_ file in the root folder of your site’s folder, as of Site.js version 17.0.0, it will load any routes defined inthat file first before looking for any file-based DotJS routes.
1434
1436
1435
-
If Site.js cannot find a _routes.js_ file, it will look to see if separate _.https_ and _.wss_ folders have been defined (the existence of just one of these is enough) and attempt to load DotJS routes from those folders. (If it finds separate _.get_ or _.post_ folders within the _.https_ folder, it will add the relevant routes from those folders;if it can’t it will load GET-only routes from the _.https_ folder and its subfolders.)
1437
+
Next Site.js, will look to see if separate _.https_ and _.wss_ folders have been defined (the existence of just one of these is enough) and attempt to load DotJS routes from those folders. (If it finds separate _.get_ or _.post_ folders within the _.https_ folder, it will add the relevant routes from those folders;if it can’t it will load GET-only routes from the _.https_ folder and its subfolders.)
1436
1438
1437
1439
If separate _.https_ and _.wss_ folders do not exist, Site.js will expect all defined DotJS routes to be HTTPS and will initially look for separate _.get_ and _.post_ folders (the existence of either is enough to trigger this mode). If they exist, it will add the relevant routes from those folders and their subfolders.
The code within your JavaScript routes is executed on the server. Exercise the same caution as you would when creating any Node.js app (sanitise input, etc.)
1464
1466
1467
+
### Creating an Admin page.
1468
+
1469
+
Given that Site.js is for single-tenant apps and sites, you can create an admin page for your site/app using the same convention that Site.js itself uses for the statistics route: by using a cryptographically secure path for it. In fact, Site.js will hide the path from your statistics view if you adhere to the convention of creating it at _/admin/cryptographically-secure-path_. Unlike the statistics URL, you will have to implement this functionality using the advanced routing feature. e.g.,
1470
+
1471
+
```js
1472
+
const crypto = require('crypto')
1473
+
1474
+
// Create a cryptographically-secure path for the admin route
1475
+
// and save it in a table called admin in the built-in JSDB database.
As of version 14.5.0, if all you want to do is to customise the behaviour of your pages using client-side JavaScript based on parameters provided through the URL path, you don’t have to use dynamic routes and a `routes.js` file, you can use wildcard routes instead, which are much simpler.
0 commit comments