Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add-api-proxy: Add Nitro server API routes #179

Merged
merged 34 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95e6897
feat: add-api-proxy: Add Nitro server API routes
vloss3 Oct 19, 2023
0486f4a
Remove debug code
vloss3 Oct 19, 2023
dc67d86
Fix tests
vloss3 Oct 19, 2023
0817411
Fix menu route rules and add docs
vloss3 Oct 26, 2023
1117aad
Add test for disabled exposeAPIRouteRules
vloss3 Oct 26, 2023
d3927a8
Improve docs
vloss3 Oct 26, 2023
1d6c9a6
Improve docs
vloss3 Oct 26, 2023
cca49d1
Merge remote-tracking branch 'origin/2.x' into feature/165-add-api-proxy
vloss3 Oct 26, 2023
72220f4
Fix module build error.
TurtlBbx Oct 27, 2023
8409bce
Fix menu proxy not working.
TurtlBbx Oct 27, 2023
003b311
add-api-proxy: Add README and add BC baseUrl
vloss3 Nov 23, 2023
bee448c
add-api-proxy: Replace routeRules with server handlers
vloss3 Dec 6, 2023
1bf7fc8
add-api-proxy: Remove console log
vloss3 Dec 6, 2023
da133ce
add-api-proxy: Handle cases where baseURL is not full URL
vloss3 Dec 6, 2023
f454685
add-api-proxy: Add back README commit
vloss3 Dec 6, 2023
82c5d53
add-api-proxy: Support i18n in menus and add README for runtime overr…
vloss3 Dec 12, 2023
c9feacf
add-api-proxy: Add override examples and use serverDrupalBaseUrl
vloss3 Dec 12, 2023
4384241
add-api-proxy: Improve README
vloss3 Dec 13, 2023
ad8d084
Improve README
TurtlBbx Dec 14, 2023
24b5ec9
Fix a build error
TurtlBbx Dec 14, 2023
03ea4cd
Fix build errors
TurtlBbx Dec 14, 2023
f0352c4
Fix menu endpoint proxy
TurtlBbx Dec 14, 2023
51a8ac6
Improve README
TurtlBbx Dec 14, 2023
401a753
Fix default options
TurtlBbx Dec 14, 2023
2ea6a68
Update README.md
fago Dec 15, 2023
8c098c4
correctly test BC
fago Dec 15, 2023
80908d2
add-api-proxy: Update README and menu fallback
vloss3 Jan 2, 2024
a3940c4
Merge remote-tracking branch 'origin/2.x' into feature/165-add-api-proxy
vloss3 Jan 17, 2024
f5a39ae
add-api-proxy: Allow env overrides for drupalBaseUrl
vloss3 Jan 17, 2024
2ac578f
add-api-proxy: Update vitest
vloss3 Jan 17, 2024
476d1cd
add-api-proxy: Improve menu route and README
vloss3 Jan 18, 2024
07f0064
add-api-proxy: Small refactor
vloss3 Jan 22, 2024
d1ab251
add-api-proxy: Refactor menu api code
vloss3 Jan 23, 2024
cf1dc10
add-api-proxy: Add handler for base path
vloss3 Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ rm -f app.vue && npx nuxt-drupal-ce-init
* Provides unstyled skeleton components for getting started quickly.
* Supports fetching and display of Drupal menus via the [Rest menu items](https://www.drupal.org/project/rest_menu_items) module.


## Options

- `baseURL`: The Drupal base URL. Defaults to the `DRUPAL_BASE_URL`
environment variable if provided, otherwise to `http://localhost:8888`.
- `drupalBaseUrl`: The Drupal base URL.

- `serverDrupalBaseUrl`: Optionally, an alternative drupal base URL to apply in server context.

- `ceApiEndpoint`: The custom elements API endpoint. Defaults to `/ce-api`.

- `fetchOptions`: The default [fetchOptions](https://nuxt.com/docs/api/composables/use-fetch#params)
to apply when fetching from the Drupal. Defaults to `{ credentials: 'include' }`.
Expand All @@ -74,6 +78,8 @@ rm -f app.vue && npx nuxt-drupal-ce-init
to the API provided by the [Rest menu items](https://www.drupal.org/project/rest_menu_items) Drupal module.
`$$$NAME$$$` is replaced by the menu name being fetched.

- `menuBaseUrl`: The menu base URL. Defaults to drupalBaseUrl + ceApiEndpoint.

- `addRequestContentFormat`: If specified, the given value is added as `_content_format`
URL parameter to requests. Disabled by default.

Expand All @@ -86,6 +92,23 @@ is added automatically to requests. Defaults to `false`.

- `useLocalizedMenuEndpoint`: If enabled, the menu endpoint will use a language prefix as configured by [nuxtjs/i18n](https://v8.i18n.nuxtjs.org) module. Defaults to `true`.

- `exposeAPIRouteRules`: If enabled, the module will create a Nitro server handler that proxies API requests to Drupal backend. Defaults to `true` for SSR (it's disabled for SSG).

## Overriding options with environment variables
Runtime config values can be overridden with environment variables via `NUXT_PUBLIC_` prefix. Supported runtime overrides:

- `baseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_BASE_URL`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this documents an override for the deprecated optiln. it should document it for drupalbaseUrl

Copy link
Contributor

@TurtlBbx TurtlBbx Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fago @vloss3 In code, we don't support ENV override of drupalBaseUrl. It's not taken into account, as seen here.

We either:
a) Change back in README to state that we support baseUrl (and not drupalBaseUrl) override (it's used in the server proxy handler).
b) Change the code to support drupalbaseUrl override and leave the README as-is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We need to have that kind of override working, this is critical functionaliaty, we cannot merge without it.
  • The module had code merge in runtimeconfig and make it override regular config before. maybe this is still there and working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed drupalBaseUrl to work with env overrides

- `serverDrupalBaseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_SERVER_DRUPAL_BASE_URL`
- `menuBaseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_MENU_BASE_URL`

TurtlBbx marked this conversation as resolved.
Show resolved Hide resolved
## Deprecated options

The following options are deprecated and only there for improved backwards compatibility.

- `baseURL`: The base URL of the Drupal /ce-api endpoint, e.g. http://localhost:8888/ce-api.
If set, `drupalBaseUrl` is set with the origin of the provided URL.


## Error handling

The module provides a default error handler for the `fetchPage` and `fetchMenu` methods:
Expand Down
Loading