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

Update and improve the Next.js example #6442

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3e99e54
Updated dependencies
pnicolli Oct 7, 2024
dc12a99
Updated app conf
pnicolli Oct 7, 2024
3ffdad2
Fixed more deps and configs
pnicolli Oct 7, 2024
2bd2768
Working PoC
pnicolli Oct 8, 2024
1bd21a6
Merge branch 'main' into pnicolli-nextjs
pnicolli Oct 9, 2024
51e9f04
Cleanup lockfile
pnicolli Oct 9, 2024
dccb8b7
Basic layout and usage of client packages
pnicolli Oct 9, 2024
857c572
Load add-ons
pnicolli Oct 15, 2024
3c2d43b
Merge branch 'main' into pnicolli-nextjs
pnicolli Oct 15, 2024
d35e4e6
Added slots
pnicolli Oct 15, 2024
fc47f5e
Merge branch 'main' into pnicolli-nextjs
pnicolli Oct 26, 2024
5377fd6
Merge branch 'main' into pnicolli-nextjs
pnicolli Oct 29, 2024
4dccbeb
fix imports and disable broken addons import
pnicolli Oct 29, 2024
0ee4718
Moved custom next config to a plugin
pnicolli Oct 30, 2024
1a09f3a
Merge branch 'main' into pnicolli-nextjs
pnicolli Nov 1, 2024
7c47d38
Merge branch 'main' into pnicolli-nextjs
pnicolli Nov 5, 2024
79e2ce9
Added empty new package
pnicolli Nov 5, 2024
485c481
Merge branch 'main' into pnicolli-nextjs
pnicolli Nov 14, 2024
d8b1187
Merge branch 'main' into pnicolli-nextjs
pnicolli Nov 19, 2024
955a632
Added base theme and use registry properly
pnicolli Nov 19, 2024
bd941ec
Merge branch 'main' into pnicolli-nextjs
pnicolli Nov 21, 2024
69cc21e
Fixed config, it works again
pnicolli Nov 23, 2024
a2a1120
Updated lockfile
pnicolli Nov 23, 2024
ed85932
Updated packages, streamlined nextjs app code
pnicolli Nov 26, 2024
c178396
Cleanup
pnicolli Nov 28, 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
54 changes: 3 additions & 51 deletions apps/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
// import path from 'path';
import { withPlone } from '@plone/nextjs/plugin';

/** @type {import('next').NextConfig} */
const nextConfig = {
const nextConfig = withPlone({
typescript: {
ignoreBuildErrors: true,
},
// sassOptions: {
// includePaths: [path.join(__dirname, 'src/lib/components/src/styles')],
// },

// webpack(config) {
// config.resolve.alias = {
// ...config.resolve.alias,
// '../fonts': path.resolve(__dirname, 'src/lib/components/src/fonts'),
// };

// return config;
// },

// Rewrite to the backend to avoid CORS
async rewrites() {
let apiServerURL, vhmRewriteRule;
if (
process.env.API_SERVER_URL &&
(process.env.NEXT_PRODUCTION_URL || process.env.NEXT_PUBLIC_VERCEL_URL)
) {
// We are in Vercel
apiServerURL = process.env.API_SERVER_URL;
vhmRewriteRule = `/VirtualHostBase/https/${
process.env.NEXT_PRODUCTION_URL
? // We are in the production deployment
process.env.NEXT_PRODUCTION_URL
: // We are in the preview deployment
process.env.NEXT_PUBLIC_VERCEL_URL
}%3A443/Plone/%2B%2Bapi%2B%2B/VirtualHostRoot`;
} else if (process.env.API_SERVER_URL) {
// We are in development
apiServerURL = process.env.API_SERVER_URL;
vhmRewriteRule =
'/VirtualHostBase/http/localhost%3A3000/Plone/%2B%2Bapi%2B%2B/VirtualHostRoot';
} else {
// We are in development and the API_SERVER_URL is not set, so we use a local backend
apiServerURL = 'http://localhost:8080';
vhmRewriteRule =
'/VirtualHostBase/http/localhost%3A3000/Plone/%2B%2Bapi%2B%2B/VirtualHostRoot';
}

return [
{
source: '/\\+\\+api\\+\\+/:slug*',
destination:
// 'https://static.197.123.88.23.clients.your-server.de/api/:slug*',
// `${apiServerURL}/:slug*`,
`${apiServerURL}${vhmRewriteRule}/:slug*`,
},
];
},
};
});

export default nextConfig;
9 changes: 9 additions & 0 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
"start:prod": "next start",
"lint": "next lint"
},
"addons": [
"@plone/blocks",
"@plone/slots",
"@plone/quanta"
],
"dependencies": {
"@plone/blocks": "workspace: *",
"@plone/client": "workspace: *",
"@plone/components": "workspace: *",
"@plone/nextjs": "workspace: *",
"@plone/providers": "workspace: *",
"@plone/quanta": "workspace:^",
"@plone/registry": "workspace: *",
"@plone/slots": "workspace: *",
"@tanstack/react-query": "^5.59.0",
"clsx": "^2.1.1",
"next": "14.2.14",
"react": "^18",
"react-aria-components": "^1.4.0",
Expand Down
78 changes: 0 additions & 78 deletions apps/nextjs/src/app/Providers.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions apps/nextjs/src/app/[...slug]/page.tsx

This file was deleted.

74 changes: 74 additions & 0 deletions apps/nextjs/src/app/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import App from '@plone/slots/components/App';
import Providers from '@/components/providers/Providers';
import { getServerQueryClient, client as ploneClient } from '@/helpers/client';
import cx from 'clsx';
import { Inter } from 'next/font/google';

const expand = ['navroot', 'breadcrumbs', 'navigation', 'site'];

const inter = Inter({ subsets: ['latin'] });

export async function generateMetadata({
params,
}: {
params: { slug?: string[] };
}) {
const { slug = [] } = params;
const path = '/' + slug.join('/');
const queryClient = getServerQueryClient();
const { getContentQuery } = ploneClient;
const data = await queryClient.fetchQuery(getContentQuery({ path, expand }));

return {
title: `${data.title || ''} - Next.js app powered by Plone`,
description: data.description,
};
}

export default async function Main({
params,
searchParams,
}: {
params: { slug?: string[] };
searchParams: { [key: string]: string | string[] | undefined };
}) {
const { slug = [] } = params;
const path = '/' + slug.join('/');
const queryClient = getServerQueryClient();
const { getContentQuery } = ploneClient;
const content = await queryClient.fetchQuery(
getContentQuery({ path, expand }),
);
const search = new URLSearchParams();
Object.entries(searchParams).forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach((v) => search.append(key, v));
} else if (value) {
search.append(key, value);
}
});
const location = {
pathname: path,
search: search.toString(),
hash: '',
state: null,
key: '',
};

const className = cx(
inter.className,
`view-${content.layout ?? 'view'}`,
`contenttype-${content['@type'].replace(' ', '').toLowerCase()}`,
`section-${slug[slug.length - 1] || 'home'}`,
);

return (
<html lang={content.language?.token || 'en'}>
<body className={className}>
<Providers>
<App content={content} location={location} />;
</Providers>
</body>
</html>
);
}
30 changes: 0 additions & 30 deletions apps/nextjs/src/app/config.ts

This file was deleted.

33 changes: 0 additions & 33 deletions apps/nextjs/src/app/content.tsx

This file was deleted.

Binary file modified apps/nextjs/src/app/favicon.ico
Binary file not shown.
15 changes: 0 additions & 15 deletions apps/nextjs/src/app/getQueryClient.tsx

This file was deleted.

31 changes: 13 additions & 18 deletions apps/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import Providers from './Providers';
import type { Viewport } from 'next';
import '@plone/theming/styles/main.css';
import '@plone/slots/main.css';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'Next.js app powered by Plone',
description: '',
export const viewport: Viewport = {
themeColor: '#fff',
minimumScale: 1,
initialScale: 1,
width: 'device-width',
viewportFit: 'cover',
};

export default function RootLayout({
export default async function RootLayout({
children,
}: {
}: Readonly<{
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={inter.className}>
<Providers>{children}</Providers>
</body>
</html>
);
}>) {
return children;
}
32 changes: 0 additions & 32 deletions apps/nextjs/src/app/main.tsx

This file was deleted.

Loading
Loading