Skip to content

Commit

Permalink
#38: WiP, close to first contentBase fetch and rendering. Make fetch …
Browse files Browse the repository at this point in the history
…client-side to view it better.
  • Loading branch information
espen42 committed Sep 1, 2021
1 parent 5da22fe commit dc0832c
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

const portalLib = require('/lib/xp/portal');
const { getContentData } = require('../contentapi/contentdata');
const { getContentData } = require('../../lib/headless/contentapi/contentdata');

const handlePost = (req) => {
// query: HIGHLY RECOMMENDED: supply a query to override the fallback catch-all query with a BETTER SCALING, content-type-specific one.
Expand Down Expand Up @@ -31,3 +31,6 @@ const handlePost = (req) => {
};

exports.post = handlePost;

// FIXME: only for testing, remove.
exports.get = handlePost;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

const portalLib = require('/lib/xp/portal');
const { getContentBase } = require('../contentapi/contentbase');
const { getContentBase } = require('../../lib/headless/contentapi/contentbase');

const handleGet = (req) => {
const handlePost = (req) => {
// idOrPath (mandatory if no override query is used): used in the default query. Can be a valid content UUID, or a (full) content path, eg. /mysite/persons/someone. Can be supplied direct param as here, or as part of the variables param (direct param has prescendence)
// variables: optional additional variables for a supplied query, or just idOrPath.
// query: optional override for the DEFAULT_BASE_QUERY.
Expand All @@ -31,4 +31,7 @@ const handleGet = (req) => {
return getContentBase(siteId, branch, idOrPath, query, variables, maxChildren);
};

exports.get = handleGet;
exports.post = handlePost;

// FIXME: only for testing, remove.
exports.get = handlePost;
56 changes: 0 additions & 56 deletions hmdb/src/main/resources/controllers/graphql.js

This file was deleted.

96 changes: 0 additions & 96 deletions hmdb/src/main/resources/controllers/info.js

This file was deleted.

13 changes: 0 additions & 13 deletions hmdb/src/main/resources/controllers/preview.html

This file was deleted.

22 changes: 0 additions & 22 deletions hmdb/src/main/resources/controllers/preview.js

This file was deleted.

10 changes: 10 additions & 0 deletions hmdb/src/main/resources/lib/headless/contentapi/validation.es6
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ exports.idOrPathOrQueryInvalidError400 = (variables, query, message) => {
}

exports.contentNotFoundError404 = (content, variables, query) => {

// TODO: move to next site - it must parse the result and handle deeper 404 itself:
/*
// The content data on a found content will be under data.guillotine[key] - where key is determined by the query and therefore unpredictable.
// Not-found content will still yield data.guillotine, but the value under [key] will be null.
// So to detect content not found, look for null value under that key, or a result not on that shape.
const output = content?.data.guillotine || {};
const key = Object.keys(output)[0];
*/

if (!content) {
if (!query) {
log.warning(`Content not found at idOrPath = ${JSON.stringify(variables.idOrPath)}`);
Expand Down
12 changes: 6 additions & 6 deletions hmdb/src/main/resources/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
<x-data name="SoMe" allowContentTypes="person|movie"/>
<form/>
<mappings>
<mapping controller="/lib/headless/controllers/frontend-proxy.js">
<mapping controller="/controllers/frontend-proxy.js">
<match>type:'portal:fragment'</match>
</mapping>
<!--mapping controller="/lib/headless/controllers/frontend-proxy.js">
<match>type:'portal:site'</match>
</mapping-->
<mapping controller="/lib/headless/controllers/frontend-proxy.js">
<mapping controller="/controllers/frontend-proxy.js">
<match>type:'base:folder'</match>
</mapping>
<mapping controller="/lib/headless/controllers/frontend-proxy.js">
<mapping controller="/controllers/frontend-proxy.js">
<!-- Keep up to date with appname in gradle.properties -->
<match>type:'com.enonic.nextpoc.hmdb:.*'</match>
</mapping>
<mapping controller="/lib/headless/controllers/_graphql.js" order="50">
<mapping controller="/controllers/_graphql.js" order="50">
<pattern>/_graphql</pattern>
</mapping>
<mapping controller="/lib/headless/controllers/_contentbase.js" order="50">
<mapping controller="/controllers/contentapi/_contentbase.js" order="50">
<pattern>/_contentbase</pattern>
</mapping>
<mapping controller="/lib/headless/controllers/_content.js" order="50">
<mapping controller="/controllers/contentapi/_content.js" order="50">
<pattern>/_content</pattern>
</mapping>
</mappings>
Expand Down
27 changes: 21 additions & 6 deletions next/enonic.connection.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
export const appName = "com.enonic.nextpoc.hmdb"; // <-- appName in hmdb/gradle.properties
export const appNameUnderscored = appName.replace(/\./g, '_');
export const appNameDashed = appName.replace(/\./g, '-');
export const project = 'hmdb'; // <-- project identifier in path, e.g. 'default' in the URL <domain>/site/default/master
export const appKey = "com.enonic.nextpoc.hmdb"; // <-- full app key = appName in hmdb/gradle.properties

export const appNameUnderscored = appKey.replace(/\./g, '_');
export const appNameDashed = appKey.replace(/\./g, '-');

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

export const apiServiceRoot = `_/service`;
export const apiServiceName = 'sitecontent';
export const apiContentBase = '_contentbase';
export const apiContentFull = '_content';

export const siteRootUrlMaster = `${apiDomain}/site/${project}/master`;
export const siteRootUrlDraft = `${apiDomain}/site/${project}/draft`;

export const apiUrl = `${apiDomain}/${apiServiceRoot}/${appName}/${apiServiceName}`;
// appName is the content _name of the root site content-item:
export const contentApiUrlGetters = {
master: {
base: (appName) => `${siteRootUrlMaster}/${appName}/${apiContentBase}`,
full: (appName) => `${siteRootUrlMaster}/${appName}/${apiContentFull}`
},
draft: {
base: (appName) => `${siteRootUrlDraft}/draft/${appName}/${apiContentBase}`,
full: (appName) => `${siteRootUrlDraft}/draft/${appName}/${apiContentFull}`
}
};
3 changes: 3 additions & 0 deletions next/src/pages/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Custom404() {
return <h1>404 - Page Not Found</h1>
}
7 changes: 7 additions & 0 deletions next/src/pages/500.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// pages/500.js
export default function Custom500({message}) {
return <>
<h1>500 - Server-side error occurred</h1>
{message && <p>{message}</p>}
</>
}
Loading

0 comments on commit dc0832c

Please sign in to comment.