Skip to content

Commit 0c3ec4b

Browse files
authored
Merge pull request #243 from wunderio/NEX-127-1
NEX-127: Switch from pages router to app router
2 parents 88a8ad9 + 78f03ad commit 0c3ec4b

File tree

349 files changed

+8613
-9177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+8613
-9177
lines changed

.circleci/config.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ commands:
9595
if [[ $DRUPAL_ADMIN_PWD == *"not_secure_used_only_locally"* ]] \
9696
|| [[ $DRUPAL_CLIENT_SECRET == *"not_secure_used_only_locally"* ]] \
9797
|| [[ $DRUPAL_REVALIDATE_SECRET == *"not_secure_used_only_locally"* ]] \
98-
|| [[ $NEXTAUTH_SECRET == *"not_secure_used_only_locally"* ]]; then
98+
|| [[ $AUTH_SECRET == *"not_secure_used_only_locally"* ]]; then
9999
echo
100100
echo "Example secrets detected in configuration, failing build."
101101
echo
@@ -138,6 +138,7 @@ commands:
138138
next_domain=$next_release_name.$project_name.$CLUSTER_DOMAIN
139139
drupal_client_id=drupal-client-id
140140
drupal_client_viewer_id=drupal-client-viewer-id
141+
elasticsearch_host=$drupal_release_name-es.$project_name
141142
142143
if [ next_domain == "main-next" ]; then
143144
next_domain=$project_name.$CLUSTER_DOMAIN
@@ -146,9 +147,10 @@ commands:
146147
echo "export NEXT_PUBLIC_DRUPAL_BASE_URL=https://$drupal_domain" >> "$BASH_ENV"
147148
echo "export NEXT_IMAGE_DOMAIN=$drupal_domain" >> "$BASH_ENV"
148149
echo "export NEXT_PUBLIC_FRONTEND_URL=https://$next_domain" >> "$BASH_ENV"
149-
echo "export NEXTAUTH_URL=https://$next_domain" >> "$BASH_ENV"
150+
echo "export AUTH_URL=https://$next_domain" >> "$BASH_ENV"
150151
echo "export DRUPAL_CLIENT_ID=$drupal_client_id" >> "$BASH_ENV"
151152
echo "export DRUPAL_CLIENT_VIEWER_ID=$drupal_client_viewer_id" >> "$BASH_ENV"
153+
echo "export ES_HOST=$elasticsearch_host" >> "$BASH_ENV"
152154
153155
echo "Expanding special variable DRUPAL_DOMAIN = $drupal_domain ..."
154156
sed -i -e "s/<|DRUPAL_DOMAIN|>/$drupal_domain/g" $envvars_file
@@ -158,20 +160,23 @@ commands:
158160
159161
echo "Expanding special variable DRUPAL_CLIENT_ID = $drupal_client_id ..."
160162
sed -i -e "s/<|DRUPAL_CLIENT_ID|>/$drupal_client_id/g" $envvars_file
163+
164+
echo "Expanding special variable ES_HOST = $elasticsearch_host ..."
165+
sed -i -e "s/<|ES_HOST|>/$elasticsearch_host/g" $envvars_file
161166
162167
echo "Expanding special variable DRUPAL_CLIENT_VIEWER_ID = $drupal_client_viewer_id ..."
163168
sed -i -e "s/<|DRUPAL_CLIENT_VIEWER_ID|>/$drupal_client_viewer_id/g" $envvars_file
164169
165-
echo "Expanding secrets DRUPAL_CLIENT_SECRET, DRUPAL_REVALIDATE_SECRET, NEXTAUTH_SECRET & HASHSALT = <redacted> ..."
170+
echo "Expanding secrets DRUPAL_CLIENT_SECRET, DRUPAL_REVALIDATE_SECRET, AUTH_SECRET & HASHSALT = <redacted> ..."
166171
escaped_drupal_revalidate_secret=$(printf '%s\n' "$DRUPAL_REVALIDATE_SECRET" | sed -e 's/[\/&]/\\&/g')
167172
escaped_drupal_client_secret=$(printf '%s\n' "$DRUPAL_CLIENT_SECRET" | sed -e 's/[\/&]/\\&/g')
168173
escaped_drupal_client_viewer_secret=$(printf '%s\n' "$DRUPAL_CLIENT_VIEWER_SECRET" | sed -e 's/[\/&]/\\&/g')
169-
escaped_nextauth_secret=$(printf '%s\n' "$NEXTAUTH_SECRET" | sed -e 's/[\/&]/\\&/g')
174+
escaped_nextauth_secret=$(printf '%s\n' "$AUTH_SECRET" | sed -e 's/[\/&]/\\&/g')
170175
escaped_hashsalt=$(printf '%s\n' "$HASHSALT" | sed -e 's/[\/&]/\\&/g')
171176
sed -i -e "s/\${DRUPAL_CLIENT_SECRET}/$escaped_drupal_client_secret/g" $envvars_file
172177
sed -i -e "s/\${DRUPAL_CLIENT_VIEWER_SECRET}/$escaped_drupal_client_viewer_secret/g" $envvars_file
173178
sed -i -e "s/\${DRUPAL_REVALIDATE_SECRET}/$escaped_drupal_revalidate_secret/g" $envvars_file
174-
sed -i -e "s/\${NEXTAUTH_SECRET}/$escaped_nextauth_secret/g" $envvars_file
179+
sed -i -e "s/\${AUTH_SECRET}/$escaped_nextauth_secret/g" $envvars_file
175180
sed -i -e "s/\${HASHSALT}/$escaped_hashsalt/g" $envvars_file
176181
177182
echo "Expanding special variable DRUPAL_ADMIN_PWD = <redacted> ..."

.ddev/config.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ web_environment:
3636
- NEXT_IMAGE_DOMAIN=next-drupal-starterkit.ddev.site
3737
- NEXT_PUBLIC_FRONTEND_URL=https://next-drupal-starterkit.ddev.site:3000
3838
# Environment variables for next_auth:
39-
- NEXTAUTH_SECRET=nextauth_secret_not_secure_used_only_locally
40-
- NEXTAUTH_URL=https://next-drupal-starterkit.ddev.site:3000
41-
- # Environment variables for redis
39+
- AUTH_SECRET=nextauth_secret_not_secure_used_only_locally
40+
- AUTH_TRUST_HOST=true
41+
- AUTH_URL=https://next-drupal-starterkit.ddev.site:3000
42+
# Environment variables for redis
4243
- REDIS_HOST=redis
4344
- REDIS_PASS=redis
45+
# Environment variables for elasticsearch
46+
- ES_HOST=elasticsearch
4447

4548
corepack_enable: false
4649
web_extra_exposed_ports:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ node_modules
2121
# Ignore start.sh script status file
2222
.last_successful_command_ddev
2323
.last_successful_command_lando
24+
25+
Makefile

.lando.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ tooling:
4848
user: www-data
4949
cmd:
5050
- appserver: "php /app/drupal/vendor/bin/phpunit -c /app/drupal/phpunit.xml --testdox"
51+
5152
regenerate-phpunit-config:
5253
description: "Regenerates fresh PHPUnit configuration."
5354
cmd:
5455
- appserver: /app/.lando/phpunit.sh
56+
5557
xdebug:
5658
description: "Loads Xdebug in the selected mode"
5759
cmd:
@@ -153,10 +155,16 @@ services:
153155
NEXT_IMAGE_DOMAIN: next-drupal-starterkit.lndo.site
154156
NEXT_PUBLIC_FRONTEND_URL: https://frontend.lndo.site
155157
# Environment variables for next_auth:
156-
NEXTAUTH_SECRET: nextauth_secret_not_secure_used_only_locally
157-
NEXTAUTH_URL: https://frontend.lndo.site
158+
# Environment variables for next_auth:
159+
AUTH_SECRET: nextauth_secret_not_secure_used_only_locally
160+
AUTH_TRUST_HOST: true
161+
AUTH_URL: https://frontend.lndo.site
158162
REDIS_HOST: redis
159163
REDIS_PASS: "mypassword"
164+
165+
ES_HOST: elasticsearch
166+
# To enable nesh cache debugging
167+
# NEXT_PRIVATE_DEBUG_CACHE: 1
160168
build:
161169
- "cd next && npm ci"
162170
scanner: false

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,49 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## [3.0.0] 22.11.2024
8+
9+
New major release! 🎉
10+
11+
Major kudos to @jekku123 that has done 99% of the work for this! 🥇
12+
13+
- Switch from "pages router" to "app router" in Next.js
14+
- Update to drupal 10.3.9
15+
- Update contrib modules
16+
- Update to latest version of next-drupal (beta2) both Drupal module and npm package
17+
- Switch to Auth.js for authentication
18+
- Changes to drupalClient to extend NextDrupalBase
19+
- Switch to next-intl
20+
- Refinements for the redis integration
21+
- Implementation of Draft Mode
22+
- Directory refactoring in the /next subfolder
23+
- Revamped search functionality using searchkit
24+
- Added dark mode
25+
26+
## [2.7.0] 19.11.2024
27+
28+
- Add swrDelta config option for CDNs by @joshua-scott
29+
- Bump webpack from 5.93.0 to 5.94.0 in /next by @dependabot
30+
- NEX-172: Fix preview of previous revisions of nodes by @vermario
31+
- NEX-173: Redirect to current page after exiting preview by @jekku123
32+
- NEX-174: Do not return anything from the api preview route by @vermario
33+
- NEX-175: Add the possibility of running npx commands in lando by @vermario
34+
- NEX-170: Make example content even more clearly example content by @vermario
35+
- NEX-171: Upgrade the graphql_compose contrib module to version 2.2.1 by @vermario
36+
37+
## [2.6.0] 10.8.2024
38+
39+
- Cleanup and simplify Drupal clients by @joshua-scott
40+
- Bump ws from 8.17.0 to 8.17.1 in /next by @dependabot
41+
- Bump braces from 3.0.2 to 3.0.3 in /drupal by @dependabot
42+
- Update npm packages + Storybook config by @joshua-scott
43+
- Caching Search results by @micahsuomi
44+
- NEX-101: Improve data fetching and error handling by @joshua-scott
45+
- NEX-101: Sitemap.xml improvements by @joshua-scott
46+
- NEX-104: Add Redis for frontend caching by @vermario
47+
- NEX-165: Add patch to graphql_compose to allow for nodes with unpublished translations by @vermario
48+
- NEX-164: Upgrade to drupal 10.3.2, update contrib modules by @vermario
49+
750
## [2.5.0] 10.6.2024
851

952
- Add DDEV support

README.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This is a starter template created by [Wunder](https://www.wunder.io) for a decoupled website using the open-source [Next.js for Drupal](https://next-drupal.org/) project by [Chapter Three](https://www.chapterthree.com) and contributors.
44

5+
> ⚠️⚠️ **Now using the App router in Next.js!** 🎉 If you prefer using the pages router, we have kept the old version in the `pages-router` branch.
6+
57
## 🪂 Check out the running demo at https://next-drupal-starterkit.dev.wdr.io !
68

79
The aims of this template are:
@@ -54,7 +56,8 @@ Follow this guide to get the backend and frontend up and running. You can either
5456
```bash
5557
./setup-lando.sh
5658
```
57-
or
59+
60+
or
5861

5962
```bash
6063
./setup-ddev.sh
@@ -78,9 +81,9 @@ After the setup is complete, you can access the site at the following URLs:
7881

7982
Lando has two separate containers for the backend and frontend, so the URLs are different:
8083

81-
| Backend | Frontend |
82-
|--|--|
83-
| https://next-drupal-starterkit.lndo.site/ | https://frontend.lndo.site/ |
84+
| Backend | Frontend |
85+
| ----------------------------------------- | --------------------------- |
86+
| https://next-drupal-starterkit.lndo.site/ | https://frontend.lndo.site/ |
8487

8588
You can get a more detailed list of all the services and their urls with the command:
8689

@@ -92,9 +95,11 @@ lando info
9295

9396
DDEV has a single container for both the backend and frontend, so the URLs differ only by the port:
9497

95-
| Backend | Frontend |
96-
|--|--|
97-
| https://next-drupal-starterkit.ddev.site| https://next-drupal-starterkit.ddev.site:3000 |
98+
| Backend | Frontend |
99+
| ---------------------------------------- | --------------------------------------------- |
100+
| https://next-drupal-starterkit.ddev.site | https://next-drupal-starterkit.ddev.site:3000 |
101+
102+
> NOTE: localhost:3000 does not work in DDEV, you need to use the URL provided by DDEV above.
98103
99104
You can get a more detailed list of all the services and their urls with the command:
100105

@@ -108,7 +113,7 @@ We try to add to the template what we think are the most commonly requested feat
108113

109114
### Preview mode
110115

111-
The template is set up to allow editors to use [Preview mode](https://next-drupal.org/docs/reference/preview). Visit the node page on the Drupal side while the frontend is running to see a preview of the page.
116+
The template is set up to allow editors to use [Draft mode](https://nextjs.org/docs/app/building-your-application/configuring/draft-mode). Visit the node page on the Drupal side while the frontend is running to see a preview of the page.
112117

113118
### On-demand revalidation
114119

@@ -122,19 +127,19 @@ The Next.js site will then create the metatags using a combination of these two
122127
### Search indexing and frontend search interface
123128

124129
The site is set up to work with Elasticsearch to provide a complete search experience.
125-
The Lando setup includes spinning up an Elasticsearch instance with the required plugins. The content normalization and index handling is managed via the custom `wunder_search` module, which in turn makes use of the [Elasticsearch helper Drupal contrib module](https://www.drupal.org/project/elasticsearch_helper).
130+
Both the Lando and DDEV setups include spinning up an Elasticsearch instance with the required plugins. The content normalization and index handling is managed via the custom `wunder_search` module, which in turn makes use of the [Elasticsearch helper Drupal contrib module](https://www.drupal.org/project/elasticsearch_helper).
126131
On the frontend side, the search user uses the [Elastic UI library](https://elastic.github.io/eui/).
127132
The frontend site queries Elasticsearch via a simple proxy controller in Drupal, also provided by the included `wunder_search` custom Drupal module.
128-
The lando setup also includes [ElasticVue](https://elasticvue.com/), a tool to help you manage your Elasticsearch indexes.
133+
The included frontend search UI is provided by [Searchkit](https://www.searchkit.co/).
129134

130135
### Importable demo content
131136

132137
The template includes a Drupal migration to populate the site with a set of translated demo content and some test users. This includes paragraphs, images, videos, etc. Most of the content has been generated by AI.
133138

134139
### Multilanguage setup
135140

136-
This template is set up to use three languages: English (default), Finnish and Swedish. These languages are added in Drupal using the usual translation modules, and to the frontend using the [next-i18next](https://github.com/i18next/next-i18next) npm package.
137-
The indexing in Elasticsearch takes into consideration the language of the content for analysis. The interface is translated. (Note: translations have mostly been done with Google Translate, so don't expect perfect Finnish or Swedish... or English for that matter. 🙂 )
141+
This template is set up to use three languages: English (default), Finnish, and Swedish. These languages are added in Drupal using the standard translation modules and integrated into the frontend using the [Next-Intl](https://next-intl-docs.vercel.app/) module.
142+
The Elasticsearch indexing takes the content language into account for analysis, and the interface is fully translated. (Note: Most translations were done using Google Translate, so please expect some inaccuracies in Finnish, Swedish, and even English. 🙂)
138143

139144
### Webforms
140145

@@ -151,7 +156,7 @@ If the backend is not available momentarily, the frontend will try again to call
151156

152157
### Frontend user authentication and registration
153158

154-
The template includes the setup to allow users to log into the Drupal backend from the Next.js frontend, using [Next-Auth](https://next-auth.js.org/).
159+
The template includes the setup to allow users to log into the Drupal backend from the Next.js frontend, using [Auth.js](https://authjs.dev/).
155160

156161
- As an example, only registered users are allowed to post to the drupal `contact` webform, and parts of the interface in the frontend are available only for logged-in users.
157162
- Some test users are imported as part of the content migration (check the `users.csv' file for the credentials).
@@ -171,10 +176,19 @@ When adding or modifying queries and fragments, the codegen script needs to be r
171176

172177
Note that when there are changes on the GraphQL server schema itself, you will need to stop and start the command again to fetch the new schema definition (it will keep watching your changed files, but will only re-fetch the schema from the server when the codegen command first runs). Also, you might need to run `lando drush cr` or `ddev drush cr` to clear the Drupal cache.
173178

179+
##### VSCode extensions to work with GraphQL and TypeScript
180+
181+
We have included a `.vscode/extensions.json` file that will suggest some useful extensions to work with GraphQL and TypeScript in VSCode with full autocomplete and syntax highlighting. You can install them by clicking on the notification that appears when you open the project in VSCode.
182+
183+
Please note:
184+
1. We suggest opening the project in VSCode using the `/next` directory as the root of the project.
185+
2. The latest version of the "GraphQL: Language Feature Support" extension [currently has a bug](https://github.com/graphql/graphiql/issues/3620) that prevents it from working correctly with the `graphql-codegen` package. Make sure to install the v0.9.3 version instead.
186+
174187
#### Typesafe environment variables
175188

176-
The environment variables used by the frontend are also checked for type safety. If used correctly, a Zod error will prevent the frontend from building if the environment variables are not set according to the schema defined in `next/env.ts`. To add a new environment variable:
189+
The environment variables used by the frontend are also checked for type safety. If used correctly, a Zod error will prevent the frontend from building if the environment variables are not set according to the schema defined in `next/env.ts`.
177190

191+
To add a new environment variable:
178192
1. Add it to `.lando.yml`, under services > node > overrides > environment. or to `.ddev/config.yaml` for DDEV.
179193
2. Add it to `next/env.ts`. Note that it must be added twice there - once under server/client to define its schema, and once under `runtimeEnv` to read the actual value.
180194
3. Import it in the file where it's used with `import { env } from "@/env";` and use it like `env.MY_ENV_VAR`. At this point, your environment variable should be working locally.
@@ -184,30 +198,7 @@ The environment variables used by the frontend are also checked for type safety.
184198

185199
The Next.js frontend will query the Drupal backend to generate a `/sitemap.xml` path that can be submitted to search engines.
186200

187-
#### Redis caching
188-
189-
The project is set up to use [Redis](https://redis.io/) if available to cache the responses from the backend. Both the ddev and lando setup include redis by default.
190-
The connection between next.js and redis is handled by the [@neshca/cache-handler](https://www.npmjs.com/package/@neshca/cache-handler) package. We added custom logic to our cache handler
191-
to handle prepopulating the cache from builds for ISR. Checl the `cache-handler.mjs` file in the `next` directory for more information.
192-
193-
### Connecting to Redis in the local environment
194-
195-
You can connect to Redis and interact with it using the [redis cli](https://redis.io/docs/latest/develop/connect/cli/) in the local environment by running the following command:
196-
197-
If you are using Lando:
198-
199-
```bash
200-
lando redis-cli
201-
```
202-
203-
If you are using DDEV:
204-
205-
```bash
206-
ddev redis
207-
```
208-
209-
210-
### Testing with Cypress
201+
### Testing with Cypress (Lando only)
211202

212203
The template includes example tests to be run with Cypress. The Lando setup includes a headless browser and Cypress, so you can run the tests locally without the need to install anything else, but it won't be able to use the visual Cypress application. See below for more details.
213204

@@ -233,6 +224,23 @@ If you want to run the visual Cypress application, you will need to run cypress
233224

234225
You can then run your tests inside the Cypress application.
235226

236-
### UI library
227+
#### Redis caching
228+
229+
The project is set up to use [Redis](https://redis.io/) if available to cache the responses from the backend. Both the ddev and lando setup include redis by default.
230+
The connection between next.js and redis is handled by the [@neshca/cache-handler](https://www.npmjs.com/package/@neshca/cache-handler) package.
231+
232+
### Connecting to Redis in the local environment
233+
234+
You can connect to Redis and interact with it using the [redis cli](https://redis.io/docs/latest/develop/connect/cli/) in the local environment by running the following command:
235+
236+
If you are using Lando:
237237

238-
The `ui/` directory contains some reusable UI components that are used in the frontend. These components are based on the [Wunder Component Library](https://www.figma.com/file/i0RIoStoPOZfcqS80DLbkD/The-Component-Library), which is a collection of reusable UI components designed to be used as a shared base for many projects. The components are meant to be used as a starting point, and should be modified, added and removed as required to fit the needs of the project.
238+
```bash
239+
lando redis-cli
240+
```
241+
242+
If you are using DDEV:
243+
244+
```bash
245+
ddev redis
246+
```

drupal/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@
3838
# Ignore testing directories.
3939
/web/sites/simpletest
4040
/web/tmp
41+
42+
# Ignore configuration files.
43+
/config/

0 commit comments

Comments
 (0)