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

Use site configs in site #283

Merged
merged 64 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
771cd7d
Use site configs in site
magdalenaxm Jul 4, 2024
abdf27f
Use headers in middleware to redirect to right host, set headers for …
magdalenaxm Jul 4, 2024
22e4507
Use site config for content scope
magdalenaxm Jul 4, 2024
1b7a797
Load messages with site config and move IntlProvider to layout as dat…
magdalenaxm Jul 4, 2024
92c8cf8
Move IntlProvider file
magdalenaxm Jul 4, 2024
858201c
Remove lang sub folder
magdalenaxm Jul 4, 2024
554f129
Remove additional headers
magdalenaxm Jul 5, 2024
68f7f3d
Join site configs for languages, add language to URL
thomasdax98 Jul 11, 2024
0d06753
Add previewUrl to site config
thomasdax98 Jul 12, 2024
93b35a4
Add basePath to sitePreviewRoute
thomasdax98 Jul 12, 2024
58bcf08
Move sitemap.ts into [lang] directory
thomasdax98 Jul 14, 2024
65b36b3
Merge branch 'main' into use-site-configs-in-site
thomasdax98 Jul 15, 2024
b0a821b
Resolve conflicts
thomasdax98 Jul 15, 2024
814f582
Pass lang to getSiteConfig via param instead of x-current-language he…
thomasdax98 Jul 15, 2024
f5ffb62
Move languages outside of contentScope in site config
thomasdax98 Jul 15, 2024
a7ec737
Only make one site config per domain (and share for languages)
thomasdax98 Jul 15, 2024
606ccf6
Remove language param from getSiteConfig
thomasdax98 Jul 17, 2024
21e9ad6
Automatically determine the basePath in sitePreviewRoute
thomasdax98 Jul 17, 2024
e1cd788
Update sitePreviewRoute to be identical to the version in comet
thomasdax98 Jul 19, 2024
fdfb1de
Remove code that gets host from window
thomasdax98 Jul 19, 2024
669cd12
Add SitePreviewProvider
thomasdax98 Jul 19, 2024
a64c844
Conduct url rewrite for language in SitePreview#resolvePath (instead …
thomasdax98 Jul 19, 2024
f12b660
Move API route outside [lang] folder
thomasdax98 Jul 19, 2024
6872b13
Update packages
thomasdax98 Jul 19, 2024
3da5162
Fix linting errors
thomasdax98 Jul 19, 2024
2dd5dd1
Fix site config type errors
thomasdax98 Jul 19, 2024
26076ba
Merge branch 'update-v7-beta6' into use-site-configs-in-site
thomasdax98 Jul 19, 2024
48b7ce4
Merge branch 'main' into use-site-configs-in-site
thomasdax98 Jul 22, 2024
12443aa
Move /en redirect to page.tsx
thomasdax98 Jul 22, 2024
4067623
Remove draftMode() comment from middleware
thomasdax98 Jul 22, 2024
71063d3
Remove TODO comment
thomasdax98 Jul 22, 2024
62aacb1
Rename getHost to getHostFromHeaders
thomasdax98 Jul 22, 2024
ff43b9e
Split sitemap by domain
thomasdax98 Jul 22, 2024
2786149
Remove contentScopes from site-configs
thomasdax98 Jul 22, 2024
0c03a1f
Remove site.name
thomasdax98 Jul 22, 2024
c8e68f4
Remove TODO comment
thomasdax98 Jul 22, 2024
7cb3efb
Move IntlProvider back in [lang] dir
thomasdax98 Jul 22, 2024
9f801f7
Import ContentScope directly from site-configs
thomasdax98 Jul 22, 2024
0fe7a62
Use regex to match localhost domain
thomasdax98 Jul 22, 2024
016068b
Simplify regex
thomasdax98 Jul 23, 2024
677389d
Merge branch 'main' into use-site-configs-in-site
thomasdax98 Jul 29, 2024
0b99998
Move previewUrl back to .env but use the normal url in local mode
thomasdax98 Jul 29, 2024
0e65d0e
Attach domain to url to avoid usage of headers() which causes dynamic…
thomasdax98 Jul 29, 2024
96e2862
Don't run middleware for svg files from public folder
thomasdax98 Jul 29, 2024
b7d230d
Use siteConfig.url in sitemap.ts
thomasdax98 Jul 29, 2024
c0bce67
Exclude /assets from middleware (instead of .svg)
thomasdax98 Jul 30, 2024
6aea6a6
Don't run middleware for all URLs including a file extension
thomasdax98 Jul 30, 2024
92a663a
Add comment to different previewUrl configs
thomasdax98 Jul 30, 2024
eeae195
Fix URL rewrite in preview mode
thomasdax98 Jul 30, 2024
163c1fb
Remove unnecessary comment
thomasdax98 Jul 30, 2024
b725c26
Revert "Don't run middleware for all URLs including a file extension"
thomasdax98 Jul 30, 2024
b5bad95
Rename lang param to language
thomasdax98 Jul 30, 2024
70d58c8
Remove jose
thomasdax98 Jul 30, 2024
8b4179b
Remove wrong comment
thomasdax98 Jul 31, 2024
62acb22
Merge branch 'main' into use-site-configs-in-site
thomasdax98 Jul 31, 2024
cc0a044
Remove SiteConfig[public] from site-configs.d.ts
thomasdax98 Jul 31, 2024
51b3153
Add comment for assets in middleware
thomasdax98 Jul 31, 2024
96173ce
Add comment regarding getting domain from siteConfig in sitemap
thomasdax98 Jul 31, 2024
f15b3c1
Add <PublicEnvScript /> to RootLayout to make next-runtime-env work
thomasdax98 Jul 31, 2024
998c85f
Remove getUrlFromDomain() helper function from site config
thomasdax98 Jul 31, 2024
2ad4763
Always use localhost:3000 for preview
thomasdax98 Aug 1, 2024
0acbf18
Address concerns in getting site-config
fraxachun Aug 2, 2024
e18d39b
Remove outdated comment
nsams Aug 2, 2024
9c147f2
Merge branch 'main' into use-site-configs-in-site
fraxachun Aug 2, 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
26 changes: 21 additions & 5 deletions admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@comet/cms-admin";
import { css, Global } from "@emotion/react";
import { getMessages } from "@src/lang";
import { ContentScope } from "@src/site-configs";
import { theme } from "@src/theme";
import { HTML5toTouch } from "rdndmb-html5-to-touch";
import { DndProvider } from "react-dnd-multi-backend";
Expand All @@ -31,7 +32,7 @@ import { createApolloClient } from "./common/apollo/createApolloClient";
import { ContentScopeProvider } from "./common/ContentScopeProvider";
import { MasterHeader } from "./common/MasterHeader";
import { masterMenuData, pageTreeCategories, pageTreeDocumentTypes } from "./common/masterMenuData";
import { ConfigProvider, ContentScope, createConfig } from "./config";
import { ConfigProvider, createConfig } from "./config";
import { Link } from "./documents/links/Link";
import { Page } from "./documents/pages/Page";

Expand All @@ -57,13 +58,21 @@ export function App() {
value={{
configs: config.sitesConfig,
resolveSiteConfigForScope: (configs, scope: ContentScope) => {
const siteConfig = configs.find((config) => config.contentScope.domain === scope.domain);
const siteConfig = configs.find((config) => {
return config.domain === scope.domain;
});

if (!siteConfig) throw new Error(`siteConfig not found for domain ${scope.domain}`);

// In a deployed setting, we use one preview URL for all scopes.
// Locally, we use the site URL for each scope because setting the necessary cookies for the preview doesn't work on localhost.
// see https://github.com/vivid-planet/comet-starter/pull/283/files#r1696858091 for more infos
nsams marked this conversation as resolved.
Show resolved Hide resolved
const previewUrl = process.env.NODE_ENV === "development" ? siteConfig.url : config.previewUrl;
johnnyomair marked this conversation as resolved.
Show resolved Hide resolved
thomasdax98 marked this conversation as resolved.
Show resolved Hide resolved
return {
url: siteConfig.url,
preloginEnabled: siteConfig.preloginEnabled || false,
blockPreviewBaseUrl: `${config.previewUrl}/block-preview`,
sitePreviewApiUrl: `${config.previewUrl}/api/site-preview`,
blockPreviewBaseUrl: `${previewUrl}/block-preview`,
sitePreviewApiUrl: `${previewUrl}/api/site-preview`,
};
},
}}
Expand Down Expand Up @@ -100,7 +109,14 @@ export function App() {
<Switch>
<Route
path={`${match.path}/preview`}
render={(props) => <SitePreview {...props} />}
render={(props) => (
<SitePreview
resolvePath={(path: string, scope: ContentScope) => {
return `/${scope.language}${path}`;
}}
{...props}
/>
)}
/>
<Route
render={() => (
Expand Down
2 changes: 1 addition & 1 deletion admin/src/common/ContentScopeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useContentScopeConfig as useContentScopeConfigLibrary,
useCurrentUser,
} from "@comet/cms-admin";
import { ContentScope } from "@src/config";
import { ContentScope } from "@src/site-configs";

// convenince wrapper for app (Bind Generic)
export function useContentScope(): UseContentScopeApi<ContentScope> {
Expand Down
2 changes: 0 additions & 2 deletions admin/src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export function createConfig() {
};
}

export type ContentScope = PublicSiteConfig["contentScope"];

export type Config = ReturnType<typeof createConfig>;

const ConfigContext = createContext<Config | undefined>(undefined);
Expand Down
7 changes: 6 additions & 1 deletion api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export class AppModule {
AuthModule,
UserPermissionsModule.forRootAsync({
useFactory: (userService: UserService, accessControlService: AccessControlService) => ({
availableContentScopes: config.siteConfigs.map((siteConfig) => siteConfig.contentScope),
availableContentScopes: config.siteConfigs.flatMap((siteConfig) =>
siteConfig.languages.map((language) => ({
domain: siteConfig.domain,
language,
})),
),
userService,
accessControlService,
systemUsers: ["system"],
Expand Down
7 changes: 4 additions & 3 deletions site-configs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export type ContentScope = {
export interface SiteConfig extends BaseSiteConfig {
preloginPassword?: string;
public: {
contentScope: ContentScope;
domain: string;
languages: string[];
};
}

export type PrivateSiteConfig = ExtractPrivateSiteConfig<SiteConfig> & { contentScope: ContentScope };
export type PublicSiteConfig = ExtractPublicSiteConfig<SiteConfig> & { contentScope: ContentScope };
export type PrivateSiteConfig = ExtractPrivateSiteConfig<SiteConfig>;
export type PublicSiteConfig = ExtractPublicSiteConfig<SiteConfig>;
13 changes: 6 additions & 7 deletions site-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SiteConfig } from "./site-configs.d";

// Types for files in site-configs/
type Environment = "local" | "dev" | "test" | "staging" | "prod";
export type Config = Omit<SiteConfig, "domains" | "public"> & SiteConfig["public"] & {
export type Config = Omit<SiteConfig, "domains" | "public"> & Pick<SiteConfig["public"], "domain" | "languages"> & {
domains: {
preliminary?: string;
} & {
Expand All @@ -18,21 +18,20 @@ const getSiteConfigs = async (env: Environment): Promise<SiteConfig[]> => {
const files = (await fs.readdir(path)).filter((file) => !file.startsWith("_"));
const imports = (await Promise.all(files.map((file) => import(`${path}/${file}`)))) as { default: Config }[];
return imports.map((imprt, index) => {
const { domains, contentScope, ...site } = imprt.default;
const { domains, ...site } = imprt.default;

const ret: SiteConfig = {
return {
...site,
domains: {
main: domains[env] ?? "",
preliminary: env === "prod" ? domains["preliminary"] : undefined,
},
preloginEnabled: env === "prod" ? site.preloginEnabled : true,
public: {
contentScope,
domain: site.domain,
languages: site.languages,
}
};

return ret;
}
});
};
export default getSiteConfigs;
12 changes: 0 additions & 12 deletions site-configs/main-en.ts

This file was deleted.

8 changes: 3 additions & 5 deletions site-configs/main-de.ts → site-configs/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Config } from "../site-configs";

export default {
name: "Starter Main DE",
contentScope: {
domain: "main",
language: "de",
},
name: "Starter Main",
domain: "main",
languages: ["en", "de"],
domains: {
local: "localhost:3000",
},
Expand Down
12 changes: 0 additions & 12 deletions site-configs/secondary-en.ts

This file was deleted.

8 changes: 3 additions & 5 deletions site-configs/secondary-de.ts → site-configs/secondary.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Config } from "../site-configs";

export default {
name: "Starter Secondary DE",
contentScope: {
domain: "secondary",
language: "de",
},
name: "Starter Secondary",
domain: "secondary",
languages: ["en", "de"],
domains: {
local: "secondary.localhost:3000",
},
Expand Down
36 changes: 26 additions & 10 deletions site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"cache-manager": "^5.6.1",
"graphql": "^15.0.0",
"next": "^14.2.0",
"next-runtime-env": "^3.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-intl": "^6.0.0",
Expand Down
johnnyomair marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gql, previewParams } from "@comet/cms-site";
import { domain } from "@src/config";
import { Header } from "@src/layout/header/Header";
import { headerFragment } from "@src/layout/header/Header.fragment";
import { createGraphQLFetch } from "@src/util/graphQLClient";
Expand All @@ -12,12 +11,14 @@ export const metadata: Metadata = {
title: "Comet Starter",
};

export default async function Layout({ children, params }: PropsWithChildren<{ params: { lang: string } }>) {
// TODO support multiple domains, get domain by Host header
const { scope, previewData } = (await previewParams()) || { scope: { domain, language: params.lang }, previewData: undefined };
const graphQLFetch = createGraphQLFetch(previewData);
export default async function Layout({
children,
params: { domain, language },
}: PropsWithChildren<{ params: { domain: string; language: string } }>) {
const { previewData } = (await previewParams()) || { previewData: undefined };
const graphqlFetch = createGraphQLFetch(previewData);

const { header } = await graphQLFetch<GQLLayoutQuery, GQLLayoutQueryVariables>(
const { header } = await graphqlFetch<GQLLayoutQuery, GQLLayoutQueryVariables>(
gql`
query Layout($domain: String!, $language: String!) {
header: mainMenu(scope: { domain: $domain, language: $language }) {
Expand All @@ -27,7 +28,7 @@ export default async function Layout({ children, params }: PropsWithChildren<{ p

${headerFragment}
`,
{ domain: scope.domain, language: scope.language },
{ domain, language },
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gql, previewParams } from "@comet/cms-site";
import { domain, languages } from "@src/config";
import { documentTypes } from "@src/documents";
import { GQLPageTreeNodeScopeInput } from "@src/graphql.generated";
import { createGraphQLFetch } from "@src/util/graphQLClient";
Expand All @@ -16,18 +15,15 @@ const documentTypeQuery = gql`
}
`;

export default async function Page({ params }: { params: { path: string[]; lang: string } }) {
// TODO support multiple domains, get domain by Host header
const { scope, previewData } = (await previewParams()) || { scope: { domain, language: params.lang }, previewData: undefined };
const graphqlFetch = createGraphQLFetch(previewData);
export default async function Page({ params: { path, domain, language } }: { params: { path: string[]; domain: string; language: string } }) {
const scope = { domain, language };

if (!languages.includes(params.lang)) {
notFound();
}
const { previewData } = (await previewParams()) || { previewData: undefined };
const graphqlFetch = createGraphQLFetch(previewData);

//fetch documentType
const data = await graphqlFetch<GQLDocumentTypeQuery, GQLDocumentTypeQueryVariables>(documentTypeQuery, {
path: `/${(params.path ?? []).join("/")}`,
path: `/${(path ?? []).join("/")}`,
scope: scope as GQLPageTreeNodeScopeInput, //TODO fix type, the scope from previewParams() is not compatible with GQLPageTreeNodeScopeInput
});

Expand All @@ -39,8 +35,9 @@ export default async function Page({ params }: { params: { path: string[]; lang:

const props = {
pageTreeNodeId,
scope: scope as GQLPageTreeNodeScopeInput, //TODO fix type, the scope from previewParams() is not compatible with GQLPageTreeNodeScopeInput,
scope,
};

const { component: Component } = documentTypes[data.pageTreeNodeByPath.documentType];

return <Component {...props} />;
Expand Down
20 changes: 20 additions & 0 deletions site/src/app/[domain]/[language]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IntlProvider } from "@src/app/[domain]/[language]/IntlProvider";
import { readFile } from "fs/promises";

const messagesCache: Record<string, unknown> = {};
async function loadMessages(language: string) {
if (messagesCache[language]) return messagesCache[language];
const path = `./lang-compiled/${language}.json`;
const messages = JSON.parse(await readFile(path, "utf8"));
messagesCache[language] = messages;
return messages;
}

export default async function Page({ children, params: { language } }: { children: React.ReactNode; params: { language: string } }) {
const messages = await loadMessages(language);
return (
<IntlProvider locale={language} messages={messages}>
{children}
</IntlProvider>
);
}
File renamed without changes.
Loading
Loading