Skip to content

Commit

Permalink
#83: simplify enonic-connection-config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
espen42 committed Oct 18, 2021
1 parent 1474cf6 commit 9cad670
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
18 changes: 5 additions & 13 deletions src/enonic-connection-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@ const mode = DEVELOPMENT;


/** XP server domain, incl. protocol:// and :port. Eg. 'localhost:8080' in localhost:8080/site/default/draft/mysite/api */
const apiDomain = "http://hmdb-draft:8080";

const apiDomain = "http://localhost:8080";

/** Which site this server communicates with: content item _name for the root site item */
const siteName = 'hmdb';

/** Branch-specific (and domain-less) root URL to the XP site content, sensitive to XP vhosting. Eg. 'site/default/draft/mysite' in localhost:8080/site/default/draft/mysite */
const siteRoot = ''; //`site/hmdb/draft/${siteName}`;

/** Mapped pattern to the controller of of the API, eg. 'api' in localhost:8080/site/default/draft/mysite/api */
const apiPostfix = '_guillotine';
/** URL to the guillotine API */
const contentApiUrl = `${apiDomain}/site/hmdb/draft/${siteName}/api`;

/** full app key = appName in gradle.properties in the XP app */
const appKey = "com.example.myproject";

/** The domain (full: with protocol and port if necessary) of this next.js server */
const nextDomain = "http://localhost:3000";

/** Where requests from XP CS previews (requesting next renderings) will come from */
/** Where requests from XP CS previews (requesting next renderings) will come from. Identical out of the box, but may not always be. */
const xpPreviewOrigin = apiDomain;

const FROM_XP_PARAM = '__fromXp__';


const siteUrl = `${apiDomain}/${siteRoot}`;
const contentApiUrl = `${siteUrl}/${apiPostfix}`;
const FROM_XP_PARAM = '__fromXp__';

const publicPattern = new RegExp('^/*');

Expand All @@ -42,7 +35,6 @@ module.exports = {
apiDomain,
xpPreviewOrigin,
siteName,
siteRoot,
contentApiUrl,
fromXpParam: FROM_XP_PARAM,

Expand Down
8 changes: 5 additions & 3 deletions src/shared/data/fetchContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export type ContentResult = Result & {

type FetcherConfig<T extends {
contentApiUrl: string,
getXpPath: (siteRelativeContentPath: string) => string
getXpPath: (siteRelativeContentPath: string) => string,
fromXpParam: string
}> = {
enonicConnectionConfig: T,
typeSelector?: TypeSelector,
Expand Down Expand Up @@ -158,7 +159,7 @@ export const buildContentFetcher = <T extends {
}: FetcherConfig<T>
): ContentFetcher => {

const { contentApiUrl, getXpPath } = enonicConnectionConfig;
const { contentApiUrl, getXpPath, fromXpParam } = enonicConnectionConfig;

const defaultGetVariables: VariablesGetter = (path) => ({ path });

Expand Down Expand Up @@ -306,7 +307,8 @@ export const buildContentFetcher = <T extends {
} as ContentResult;

// .meta will be visible in final rendered inline props. Only adding .requestIsFromXp here if the page is actually viewed through content studio, in which case this is true (instead if always adding it and letting it be visible as false)
if (context?.query?.__fromXp__) {
// @ts-ignore
if ((context?.query || {})[fromXpParam]) {
// @ts-ignore
response.meta.requestIsFromXp = true
}
Expand Down

0 comments on commit 9cad670

Please sign in to comment.