diff --git a/packages/next-acms/src/get.ts b/packages/next-acms/src/get.ts new file mode 100644 index 00000000..08a6d383 --- /dev/null +++ b/packages/next-acms/src/get.ts @@ -0,0 +1,27 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +export async function get( + request: NextApiRequest, + response: NextApiResponse, + url: URL, +) { + try { + // Fetch from Drupal. + const result = await fetch(url.toString(), { + headers: { + 'Content-Type': 'application/json', + }, + }); + response.status(200); + return response.end(JSON.stringify(result)); + // return result; + // response.end(); + // console.log('RESULT', await result.json()); + // const json = await result.json(); + // console.log('RESPONSE', response.end.toString()); + // return result; + } catch (error) { + response.json(error); + response.status(405).end(); + } +} diff --git a/packages/next-acms/src/index.ts b/packages/next-acms/src/index.ts index 3e2ed129..d7a4a540 100644 --- a/packages/next-acms/src/index.ts +++ b/packages/next-acms/src/index.ts @@ -1,2 +1,4 @@ export * from './revalidate'; export * from './test-api-compatibility'; +export * from './submit'; +export * from './get'; diff --git a/packages/next-acms/src/submit.ts b/packages/next-acms/src/submit.ts new file mode 100644 index 00000000..33389109 --- /dev/null +++ b/packages/next-acms/src/submit.ts @@ -0,0 +1,25 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +export async function submit( + request: NextApiRequest, + response: NextApiResponse, + url: URL, +) { + if (request.method === 'POST') { + // Submit to Drupal. + const result = await fetch(url.toString(), { + method: 'POST', + body: JSON.stringify(request.body), + headers: { + 'Content-Type': 'application/json', + }, + }); + if (!result.ok) { + const message = await result.json(); + // Send error to client. + return response.status(result.status).json({ message }); + } + response.end(JSON.stringify(result)); + response.status(200); + } +} diff --git a/starters/basic-starter/components/node--article.tsx b/starters/basic-starter/components/node--article.tsx index 7505acc5..07e7e18c 100644 --- a/starters/basic-starter/components/node--article.tsx +++ b/starters/basic-starter/components/node--article.tsx @@ -3,8 +3,9 @@ import Link from 'next/link'; import { formatDate } from 'lib/format-date'; import { MediaImage } from 'components/media--image'; import { FormattedText } from 'components/formatted-text'; +import { Webform, WebformHeight } from 'nextjs-drupal-webform'; -export function NodeArticle({ node, ...props }) { +export function NodeArticle({ node, additionalContent, ...props }) { return (

@@ -21,6 +22,14 @@ export function NodeArticle({ node, ...props }) { ) : null} {node.created && on {formatDate(node.created)}}

+ {additionalContent.webform ? ( + + ) : null} {node.field_article_image && (
)} {entity.type === 'node--article' && ( - + )} {entity.type === 'node--event' && ( - + )} {entity.type === 'node--person' && ( - + )} {entity.type === 'node--place' && ( - + )} {entity.type === 'taxonomy_term--article_type' && (