-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: fix middleware URL generation (#6688)
* refactor(core): fix missing getBaseUrl method * refactor(core): changed URL fetch methods * refactor(core): removed unused test * refactor(core): simplified the logic for URL * Update packages/core/core/src/utils/nuxt/index.ts Co-authored-by: daaf <44862757+dawid-ziobro@users.noreply.github.com> * Update packages/core/core/src/utils/nuxt/_proxyUtils.ts Co-authored-by: Lukas Borawski <lukas.borawski@gmail.com> * refactor(core): changed the way to fetch url from config * refactor(core): added URL to generate Urls * refactor(core): removed URL checking, only validantion * refactor(nuxt-module): added URL check as a hook * refactor(nuxt-module): fixed URL generation in hook * refactor(core): slim down the code for URL generation * chore: removed non-used plugin `is-https` * refactor(core): fixed regex * refactor(core): fixed tests for new approach * refactor(nuxt-module): fixed configuration merge * refactor(nuxt-module): fixed configuration merge * refactor(nuxt-module): changed merge strategy * refactor(nuxt-module): changed merge strategy * chore: version bump for core and nuxt module * chore: version bumop for missing packages * docs: added documentation for the new release * docs: migration guide update * docs: migration guide update * docs: migration guide update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: migration guide update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: migration guide update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * refactor(nuxt-module): improved validation in server-url * refactor(core): added error if the middlewareURL fails * docs: added documentation for the new changes * refactor: moved error to url generator * chore: moved worming of missing middlwareUrl, docs update * refactor(nuxt-module): fixed host and port checking * chore: copy * chore: copy * docs: copy * revert: middlware url notation * refactor(nuxt-module): applied URL to generate url of API * refactor(nuxt-module): removed serverUrl from package * refactor(middleware): added serverUrl logic to package * chore: version bump to 2.5.12-c * feat(middleware): added missing Helmet package in nuxt and API * refactor(core): added browser URL fetch for API * chore: version bump to 2.5.12-c * refactor(middleware): added HELMET options and default * docs(middleware): added documentation for Helmet.js and middlewareUrl * refactor: fixed logging information * refactor(middleware): added missing flag to control `helmet` * chore: types * chore: version bump to 2.5.12-c * fix: configs, data transfering * chore: version bump to 2.5.12-c * docs: update * Update packages/core/docs/security/api-url.md * chore: disabling helmet by defult * test: proxyUtils base url fix * chore: helmet options object brackets * revert: console log * docs: headers-security.md update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: headers-security.md update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: headers-security.md update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: headers-security.md update Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * chore: version bump to 2.5.12-c * chore: versions alignment * docs: update api-url.md Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * docs: update api-url.md Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> * chore: removed un chaining Co-authored-by: daaf <44862757+dawid-ziobro@users.noreply.github.com> * chore: interpolation Co-authored-by: daaf <44862757+dawid-ziobro@users.noreply.github.com> * chore: types * chore: condition fix Co-authored-by: daaf <44862757+dawid-ziobro@users.noreply.github.com> Co-authored-by: Lukas Borawski <lukas.borawski@gmail.com> Co-authored-by: Filip Sobol <filipsobol@users.noreply.github.com> Co-authored-by: Filip Sobol <sobol.filip@gmail.com>
- Loading branch information
1 parent
da4dc20
commit 12feb05
Showing
23 changed files
with
3,119 additions
and
2,881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Migrating projects to 2.5.12 | ||
|
||
## Update `nuxt.config.js` | ||
|
||
In this release, we've added the optional `middlewareUrl` property to define the URL to the Server Middleware. Open the `nuxt.config.js` file and add the `middlewareUrl` property to the `publicRuntimeConfig` object as shown below. | ||
|
||
:::warning | ||
Make sure to pass the whole URL with protocol, port (if applicable), and suffix it with `/api/`. | ||
::: | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
publicRuntimeConfig: { | ||
middlewareUrl: process.env.NODE_ENV === 'production' | ||
? 'https://example.com/api/' // Your production URL | ||
: 'http://localhost:3000/api/' | ||
} | ||
} | ||
``` | ||
|
||
If you don't want to hardcode the URL in the configuration file, you can use environmental variables. | ||
|
||
Example: | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
publicRuntimeConfig: { | ||
middlewareUrl: process.env.API_BASE_URL | ||
} | ||
} | ||
``` | ||
|
||
Then add an entry in the `.env` file or use any other method for passing environmental variables that suits your needs. | ||
|
||
Example: | ||
|
||
```text | ||
// .env | ||
API_BASE_URL=https://example.com/api/ | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Server Middleware URL | ||
|
||
Internally we use Nuxt environment properties to get the URL of Server Middleware. However, you can change it by defining the `middlewareUrl` property in the `publicRuntimeConfig` object inside the `nuxt.config.js` file. | ||
|
||
:::warning | ||
Make sure to pass the whole URL with protocol, port (if applicable), and suffix it with `/api/`. | ||
::: | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
publicRuntimeConfig: { | ||
middlewareUrl: process.env.NODE_ENV === 'production' | ||
? 'https://example.com/api/' // Your production URL | ||
: 'http://localhost:3000/api/' | ||
} | ||
} | ||
``` | ||
|
||
If you don't want to hardcode the URL in the configuration file, you can use environmental variables. | ||
|
||
Example: | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
publicRuntimeConfig: { | ||
middlewareUrl: process.env.API_BASE_URL | ||
} | ||
} | ||
``` | ||
|
||
Then add an entry in the `.env` file or use any other method for passing environmental variables that suits your needs. | ||
|
||
Example: | ||
|
||
```text | ||
// .env | ||
API_BASE_URL=https://example.com/api/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# HTTP Headers security | ||
|
||
To improve the security of Vue Storefront applications, we preinstall the [Helmet](https://helmetjs.github.io/) security extension by default for Nuxt application and the [Server Middleware](/architecture/server-middleware.html). | ||
|
||
In this document we show how to change the default configuration in both applications. For a list of all available options, see the [Helmet documentation](https://helmetjs.github.io/docs/). | ||
|
||
## Configuring Helmet in Nuxt | ||
|
||
`Helmet` is disabled by default. You can enable it using the `helmet` property in the `@vue-storefront/middleware/nuxt` module configuration. You can pass `true` to enable it with the default configuration or an object to use your custom configuration. | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
modules: [ | ||
['@vue-storefront/middleware/nuxt', { | ||
helmet: true | ||
// or | ||
helmet: { | ||
// ...configuration | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
```javascript | ||
// nuxt.config.js | ||
export default { | ||
modules: [ | ||
['@vue-storefront/middleware/nuxt', { | ||
helmet: { | ||
// default configuration | ||
crossOriginOpenerPolicy: false, | ||
contentSecurityPolicy: false, | ||
crossOriginEmbedderPolicy: false, | ||
permittedCrossDomainPolicies: { | ||
permittedPolicies: 'none' | ||
} | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
## Configuring Helmet in VSF Server Middleware | ||
|
||
`Helmet` is disabled by default. You can enable it using the `helmet` property in the `middleware.config.js` file. You can either pass `true` to enable it with the default configuration or pass an object to use your custom configuration. | ||
|
||
```javascript | ||
// middleware.config.js | ||
module.exports = { | ||
helmet: { | ||
// default configuration | ||
crossOriginOpenerPolicy: false, | ||
contentSecurityPolicy: false, | ||
crossOriginEmbedderPolicy: false, | ||
permittedCrossDomainPolicies: { | ||
permittedPolicies: 'none' | ||
} | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.