Skip to content

Commit

Permalink
Revamp the RR7 app, fix all the problems related to deployments.
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Nov 19, 2024
1 parent 53cec1b commit c26f77c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 24 deletions.
8 changes: 0 additions & 8 deletions apps/rr7/app/client.ts

This file was deleted.

32 changes: 32 additions & 0 deletions apps/rr7/app/config.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This is the server side config entry point
*/
import config from '@plone/registry';
import ploneClient from '@plone/client';
import applyAddonConfiguration from '@plone/registry/addons-loader';

Check failure on line 6 in apps/rr7/app/config.server.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unable to resolve path to module '@plone/registry/addons-loader'

export default function install() {
applyAddonConfiguration(config);

config.settings.apiPath =
process.env.PLONE_API_PATH || 'http://localhost:3000';
config.settings.internalApiPath =
process.env.PLONE_INTERNAL_API_PATH || undefined;

const cli = ploneClient.initialize({
apiPath: config.settings.internalApiPath || config.settings.apiPath,
});

config.registerUtility({
name: 'ploneClient',
type: 'client',
method: () => cli,
});

console.log('API_PATH is:', config.settings.apiPath);
console.log(
'INTERNAL_API_PATH is:',
config.settings.internalApiPath || 'not set',
);
return config;
}
12 changes: 4 additions & 8 deletions apps/rr7/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* This is the client side config entry point
*/
import config from '@plone/registry';
import applyAddonConfiguration from '@plone/registry/addons-loader';

Check failure on line 5 in apps/rr7/app/config.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unable to resolve path to module '@plone/registry/addons-loader'

export default function install() {
applyAddonConfiguration(config);
config.settings.apiPath =
process.env.PLONE_API_PATH || 'http://localhost:3000';
config.settings.internalApiPath = process.env.PLONE_INTERNAL_API_PATH || '';
console.log('API_PATH is:', config.settings.apiPath);
console.log(
'INTERNAL_API_PATH is:',
config.settings.internalApiPath || 'not set',
);
config.settings.apiPath = 'http://localhost:3000';
return config;
}
32 changes: 25 additions & 7 deletions apps/rr7/app/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
useQuery,
useQueryClient,
} from '@tanstack/react-query';
import { flattenToAppURL } from './utils';
import { useLoaderData, useLocation } from 'react-router';
import type { MetaFunction } from 'react-router';
import { usePloneClient } from '@plone/providers';
import { ploneClient } from './client';
import PloneClient from '@plone/client';
import App from '@plone/slots/components/App';
import type { MetaFunction } from 'react-router';
import { flattenToAppURL } from './utils';
import config from '@plone/registry';

export const meta: MetaFunction = () => {
return [
Expand All @@ -34,11 +35,28 @@ export async function loader({ params, request }: LoaderArgs) {
},
});

const { getContentQuery } = ploneClient;
const ploneClient = config
.getUtility({
name: 'ploneClient',
type: 'client',
})
.method();

await queryClient.prefetchQuery(
getContentQuery({ path: flattenToAppURL(request.url), expand }),
);
const { getContentQuery } = ploneClient as PloneClient;

const path = flattenToAppURL(request.url);
if (
!(
/^https?:\/\//.test(path) ||
/^favicon.ico\/\//.test(path) ||
/expand/.test(path) ||
/^\/@@images/.test(path) ||
/^\/@@download/.test(path) ||
/^\/assets/.test(path)
)
) {
await queryClient.prefetchQuery(getContentQuery({ path, expand }));
}

return { dehydratedState: dehydrate(queryClient) };
}
Expand Down
5 changes: 5 additions & 0 deletions apps/rr7/app/okroute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function loader() {
return new Response(null, {
status: 200,
});
}
1 change: 1 addition & 0 deletions apps/rr7/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { index, route } from '@react-router/dev/routes';

export const routes: RouteConfig = [
index('content.tsx', { id: 'index' }),
route('ok', 'okroute.tsx', { id: 'ok' }),
route('*', 'content.tsx', { id: 'splat' }),
];
3 changes: 2 additions & 1 deletion apps/rr7/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import config from '@plone/registry';
*/
export function flattenToAppURL(url: string) {
const { settings } = config;

const result =
url &&
url
.replace(settings.apiPath, '')
.replace(settings.internalApiPath || '', '')
.replace(settings.internalApiPath, '')
.replace('http://localhost:3000', '');
return result;
}

0 comments on commit c26f77c

Please sign in to comment.