Skip to content

Commit 7edd8d4

Browse files
authored
feat: add preview side editor (#38)
* chore: rename env variables * chore: turn on future flags * feat: side editor * chore: update readme instructions * chore: new strapi exp * fix: env example files * fix: duplicate env vars * chore: upgrade strapi experimental * feat: bump strapi version * fix: generic uid in strapi package.json * fix: remove yarn integrity file * Update strapi/config/features.ts
1 parent 4fc8f51 commit 7edd8d4

File tree

10 files changed

+66
-115
lines changed

10 files changed

+66
-115
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![LaunchPad](./LaunchPad.jpg)
44

5-
Welcome aboard **LaunchPad**, the official Strapi demo application, where we launch your content into the stratosphere at the speed of *"we-can't-even-measure-it!"*.
5+
Welcome aboard **LaunchPad**, the official Strapi demo application, where we launch your content into the stratosphere at the speed of _"we-can't-even-measure-it!"_.
66
This repository contains the following:
77

88
- A Strapi project with content-types and data already onboard
@@ -12,22 +12,6 @@ This repository contains the following:
1212

1313
Strap yourself in! You can get started with this project on your local machine by following the instructions below, or you can [request a private instance on our website](https://strapi.io/demo)
1414

15-
## 🛠 Prerequisites
16-
17-
Before you take off, make sure you have the right env variables loaded for each part (rocket science at its best):
18-
19-
Strapi (example in `./strapi/.env.example`):
20-
- `STRAPI_ADMIN_CLIENT_URL=<url-of-nextjs>`
21-
- `STRAPI_ADMIN_CLIENT_PREVIEW_SECRET=<a-random-token>`
22-
23-
- Create a `./strapi/.env` file with these variables
24-
25-
Next.js (example in `./next/.env.sample`):
26-
- `NEXT_PUBLIC_API_URL=<url-of-strapi>` (mandatory)
27-
- `PREVIEW_SECRET=<the-same-random-token-as-for-strapi>`
28-
29-
- Create a `./next/.env` file with these variables
30-
3115
## 1. Clone Launchpad
3216

3317
To infinity and beyond! 🚀 Clone the repo with this command:
@@ -38,7 +22,23 @@ git clone https://github.com/strapi/launchpad.git
3822

3923
- Navigate to your project folder by running `cd launchpad`.
4024

41-
## 2. Start Strapi
25+
## 2. Set up environment variables
26+
27+
Before you take off, set up the required environment variables for both Strapi and Next.js.
28+
29+
To create the Strapi .env file, copy the content of the `./strapi/.env.example` file into a new file named `./strapi/.env`, then modify the values to match your setup:
30+
31+
```sh
32+
cp ./strapi/.env.example ./strapi/.env
33+
```
34+
35+
Then do the same for the Next.js .env file, and modify it too:
36+
37+
```sh
38+
cp ./next/.env.example ./next/.env
39+
```
40+
41+
## 3. Start Strapi
4242

4343
Take a deep breath. It's time to power up the Strapi engines. Navigate to your ./my-projects/launchpad/strapi folder by running:
4444

@@ -52,11 +52,11 @@ yarn && yarn seed && yarn develop
5252

5353
This will install dependencies, sprinkle in some data magic, and run the server. (You can run these commands separately, but why not be efficient?)
5454

55-
## 3. Start Next.js
55+
## 4. Start Next.js
5656

5757
We're almost ready for lift-off! Next.js is your sleek, futuristic interface for getting all that glorious content out into the world. 🚀
5858

59-
Navigate to your `./my-projects/launchpad/next` folder by running `cd next` from your command line.
59+
Open a new terminal tab or window to leave Strapi running, and navigate to your `./my-projects/launchpad/next` folder by running `cd next`.
6060

6161
- Run the following command in your `./launchpad/next` folder
6262

@@ -91,10 +91,9 @@ This installs dependencies, builds your project, and starts your server. You’r
9191
[Data transfer](https://strapi.io/blog/importing-exporting-and-transferring-data-with-the-strapi-cli) Streams your data from one Strapi instance to another Strapi instance.<br />
9292
[Review Worfklows](https://docs.strapi.io/user-docs/settings/review-workflows) Create and manage any desired review stages for your content, enabling your team to collaborate in the content creation flow from draft to publication. <br />
9393

94-
9594
## Resources
9695

97-
[Docs](https://docs.strapi.io)[Demo](https://strapi.io/demo)[Forum](https://forum.strapi.io/)[Discord](https://discord.strapi.io)[Youtube](https://www.youtube.com/c/Strapi/featured)[Strapi Design System](https://design-system.strapi.io/)[Marketplace](https://market.strapi.io/)[Cloud Free Trial](https://cloud.strapi.io)
96+
[Docs](https://docs.strapi.io)[Demo](https://strapi.io/demo)[Forum](https://forum.strapi.io/)[Discord](https://discord.strapi.io)[Youtube](https://www.youtube.com/c/Strapi/featured)[Strapi Design System](https://design-system.strapi.io/)[Marketplace](https://market.strapi.io/)[Cloud Free Trial](https://cloud.strapi.io)
9897

9998
## Todo
10099

@@ -109,4 +108,4 @@ This installs dependencies, builds your project, and starts your server. You’r
109108

110109
- The Strapi application contains a postinstall script that will regenerate an uuid for the project in order to get some anonymous usage information concerning this demo. You can disable it by removing the uuid inside the `./strapi/packages.json` file.
111110

112-
- The Strapi application contains a patch for the @strapi/admin package. It is only necessary for the hosted demos since we automatically create the Super Admin users for them when they request this demo on our website.
111+
- The Strapi application contains a patch for the @strapi/admin package. It is only necessary for the hosted demos since we automatically create the Super Admin users for them when they request this demo on our website.

next/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ WEBSITE_URL=http://localhost:3000 # Add the correct ENV var for this onto your h
22
PORT=3000
33

44
NEXT_PUBLIC_API_URL=http://localhost:1337
5-
PREVIEW_SECRET=the-same-random-token-as-for-strapi
5+
PREVIEW_SECRET=tobemodified

next/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Welcome to our cutting-edge Next.js Multilingual Blog Template! This powerful an
1515

1616
1. Clone this repository
1717
2. Install dependencies: `npm install`
18-
3. Copy `.env.sample` to `.env.local` and update the variables
18+
3. Copy `.env.example` to `.env.local` and update the variables
1919
4. Run the development server: `npm run dev`
2020
5. Open [http://localhost:3000](http://localhost:3000) in your browser
2121

next/app/[locale]/(marketing)/ClientSlugHandler.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect } from "react";
44
import { useSlugContext } from "@/app/context/SlugContext";
5+
import { useRouter } from "next/navigation";
56

67
export default function ClientSlugHandler({
78
localizedSlugs,
@@ -16,5 +17,26 @@ export default function ClientSlugHandler({
1617
}
1718
}, [localizedSlugs, dispatch]);
1819

20+
const router = useRouter();
21+
22+
useEffect(() => {
23+
const handleMessage = async (message: MessageEvent<any>) => {
24+
if (
25+
message.origin === process.env.NEXT_PUBLIC_API_URL &&
26+
message.data.type === "strapiUpdate"
27+
) {
28+
router.refresh();
29+
}
30+
};
31+
32+
// Add the event listener
33+
window.addEventListener("message", handleMessage);
34+
35+
// Cleanup the event listener on unmount
36+
return () => {
37+
window.removeEventListener("message", handleMessage);
38+
};
39+
}, [router]);
40+
1941
return null; // This component only handles the state and doesn't render anything.
2042
}

strapi/.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ ADMIN_JWT_SECRET=tobemodified
66
TRANSFER_TOKEN_SALT=tobemodified
77
JWT_SECRET=tobemodified
88

9-
STRAPI_ADMIN_CLIENT_URL=http://localhost:3000
10-
STRAPI_ADMIN_CLIENT_PREVIEW_SECRET=a-random-token
119

1210
CLIENT_URL=http://localhost:3000
13-
PREVIEW_SECRET=your-secret-key # optional, required with Next.js draft mode
11+
PREVIEW_SECRET=tobemodified # optional, required with Next.js draft mode

strapi/config/admin.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
export default ({ env }) => ({
22
auth: {
3-
secret: env('ADMIN_JWT_SECRET'),
3+
secret: env("ADMIN_JWT_SECRET"),
44
},
55
apiToken: {
6-
salt: env('API_TOKEN_SALT'),
6+
salt: env("API_TOKEN_SALT"),
77
},
88
transfer: {
99
token: {
10-
salt: env('TRANSFER_TOKEN_SALT'),
10+
salt: env("TRANSFER_TOKEN_SALT"),
1111
},
1212
},
1313
flags: {
14-
nps: env.bool('FLAG_NPS', true),
15-
promoteEE: env.bool('FLAG_PROMOTE_EE', true),
14+
nps: env.bool("FLAG_NPS", true),
15+
promoteEE: env.bool("FLAG_PROMOTE_EE", true),
1616
},
1717
preview: {
1818
enabled: true,
1919
config: {
20-
allowedOrigins: [env('STRAPI_ADMIN_CLIENT_URL')],
20+
allowedOrigins: [env("CLIENT_URL")],
2121
async handler(uid, { documentId, locale, status }) {
2222
const document = await strapi.documents(uid).findOne({
23-
documentId, populate: null,
23+
documentId,
24+
populate: null,
2425
fields: ["slug"],
2526
});
2627
const { slug } = document;
2728

2829
const urlSearchParams = new URLSearchParams({
29-
secret: env('STRAPI_ADMIN_CLIENT_PREVIEW_SECRET'),
30+
secret: env("PREVIEW_SECRET"),
3031
...(slug && { slug }),
3132
locale,
3233
uid,
33-
status
34+
status,
3435
});
3536

36-
const previewURL = `${env('STRAPI_ADMIN_CLIENT_URL')}/api/preview?${urlSearchParams}`
37+
const previewURL = `${env("CLIENT_URL")}/api/preview?${urlSearchParams}`;
3738

38-
return previewURL
39+
return previewURL;
3940
},
40-
}
41-
42-
}
41+
},
42+
},
4343
});

strapi/config/features.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ({ env }) => ({});

strapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
"npm": ">=6.0.0"
4444
},
4545
"license": "MIT"
46-
}
46+
}

strapi/src/admin/extensions/components/PreviewButton/index.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

strapi/yarn.lock

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9311,16 +9311,7 @@ string-argv@~0.3.1:
93119311
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
93129312
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==
93139313

9314-
"string-width-cjs@npm:string-width@^4.2.0":
9315-
version "4.2.3"
9316-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
9317-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
9318-
dependencies:
9319-
emoji-regex "^8.0.0"
9320-
is-fullwidth-code-point "^3.0.0"
9321-
strip-ansi "^6.0.1"
9322-
9323-
string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
9314+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
93249315
version "4.2.3"
93259316
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
93269317
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -9366,14 +9357,7 @@ string_decoder@~1.1.1:
93669357
dependencies:
93679358
safe-buffer "~5.1.0"
93689359

9369-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
9370-
version "6.0.1"
9371-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
9372-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
9373-
dependencies:
9374-
ansi-regex "^5.0.1"
9375-
9376-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
9360+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
93779361
version "6.0.1"
93789362
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
93799363
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -10126,7 +10110,7 @@ wordwrap@^1.0.0:
1012610110
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
1012710111
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
1012810112

10129-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
10113+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1013010114
version "7.0.0"
1013110115
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1013210116
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -10144,15 +10128,6 @@ wrap-ansi@^6.2.0:
1014410128
string-width "^4.1.0"
1014510129
strip-ansi "^6.0.0"
1014610130

10147-
wrap-ansi@^7.0.0:
10148-
version "7.0.0"
10149-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
10150-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
10151-
dependencies:
10152-
ansi-styles "^4.0.0"
10153-
string-width "^4.1.0"
10154-
strip-ansi "^6.0.0"
10155-
1015610131
wrap-ansi@^8.1.0:
1015710132
version "8.1.0"
1015810133
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)