@dwp/govuk-casa 8.2.0 → 8.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/lib/configure.js +23 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [8.2.1](https://github.com/dwp/govuk-casa/compare/8.2.0...8.2.1) (2022-05-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* preserve compatibility with existing proxy mounting methods ([41040e6](https://github.com/dwp/govuk-casa/commit/41040e6ac891ec64ce4b70328dda333178c48b99))
|
|
11
|
+
|
|
5
12
|
## [8.2.0](https://github.com/dwp/govuk-casa/compare/8.1.0...8.2.0) (2022-05-17)
|
|
6
13
|
|
|
7
14
|
|
package/dist/lib/configure.js
CHANGED
|
@@ -154,11 +154,33 @@ function configure(config = {}) {
|
|
|
154
154
|
// Using `config.mountUrl` rather than `mountUrl` here to test whether the
|
|
155
155
|
// consumer explicitly set a `mountUrl`, in which case we're dealing with
|
|
156
156
|
// backwards-compatibility mode.
|
|
157
|
+
//
|
|
158
|
+
// This intervention would not be needed for apps that omit `mountUrl` as if
|
|
159
|
+
// so, it's assumed they're following the guidance for setting up a proxy
|
|
160
|
+
// as described in `docs/guides/setup-behind-a-proxy.md`.
|
|
157
161
|
if (config.mountUrl) {
|
|
158
162
|
log.warn('[DEPRECATION WARNING] Using configuration attribute, mountUrl. This will be removed in an upcoming major version');
|
|
159
163
|
app.use((req, res, next) => {
|
|
164
|
+
// Mimic what the `docs/guides/setup-behind-a-proxy.md` guidance
|
|
165
|
+
// recommends for stripping off any proxy prefixes to leave just the
|
|
166
|
+
// "mountUrl" remaining.
|
|
167
|
+
const originalBaseUrl = req.baseUrl;
|
|
160
168
|
req.baseUrl = mountUrl.replace(/\/$/, '');
|
|
161
|
-
|
|
169
|
+
// If the app has been mounted directly on the specific `mountUrl`, then
|
|
170
|
+
// there's nothing we need to do and can let this request pass-through.
|
|
171
|
+
if (req.baseUrl === originalBaseUrl) {
|
|
172
|
+
next();
|
|
173
|
+
}
|
|
174
|
+
else if (req.__CASA_BASE_URL_REWRITTEN__) {
|
|
175
|
+
delete req.__CASA_BASE_URL_REWRITTEN__;
|
|
176
|
+
next();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// Issuing this call will re-run this same middleware, so we use this
|
|
180
|
+
// `__CASA_BASE_URL_REWRITTEN__` flag to prevent recursion.
|
|
181
|
+
req.__CASA_BASE_URL_REWRITTEN__ = true;
|
|
182
|
+
req.app.handle(req, res, next);
|
|
183
|
+
}
|
|
162
184
|
});
|
|
163
185
|
}
|
|
164
186
|
// Attach a handler to redirect requests for `/` to the first waypoint in
|