Skip to content

Commit

Permalink
refactor: use /ce-api prefix and add 404 error page to playground (#292)
Browse files Browse the repository at this point in the history
* refactor: use /ce-api prefix and add 404 error page to playground

* restore layout test

* fix tests
  • Loading branch information
fago authored Jan 14, 2025
1 parent 8da92dd commit 855fc8f
Show file tree
Hide file tree
Showing 39 changed files with 76 additions and 18 deletions.
1 change: 1 addition & 0 deletions playground/layouts/clear.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div id="main-clear">
<h1>Clear layout</h1>
<slot />
</div>
</template>
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineNuxtConfig({
compatibilityDate: '2024-12-16',
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3000',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
},
i18n: {
locales: ['en', 'de'],
Expand Down
2 changes: 1 addition & 1 deletion playground/nuxt.config4test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default defineNuxtConfig({
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3001',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
},
})
2 changes: 0 additions & 2 deletions playground/server/api/node/3.ts

This file was deleted.

25 changes: 25 additions & 0 deletions playground/server/routes/ce-api/[...].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { eventHandler, getRequestURL, setResponseStatus } from 'h3'
// Catch-all handler for /ce-api/* paths - avoids 404 endless loops.

export default eventHandler((event) => {
const url = getRequestURL(event)
setResponseStatus(event, 404)
return {
title: 'Not found',
messages: [],
breadcrumbs: [],
metatags: {
meta: [
{ name: 'title', content: 'Not found' }
],
link: []
},
content_format: 'json',
content: {
element: 'drupal-markup',
content: `API endpoint ${url.pathname} not found.`
},
page_layout: 'default',
local_tasks: []
}
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions playground/server/routes/ce-api/node/3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default defineEventHandler(() => ({
title: 'Another page',
messages: [],
breadcrumbs: [],
metatags: {
meta: [{name: 'title', content: 'Another page | lupus decoupled'}, {
name: 'description',
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Arcu dictum varius duis at consectetur. Aliquam purus sit amet luctus. Varius morbi enim nunc faucibus a pellentesque sit. Vel facilisis volutpat est velit egestas dui id ornare arcu. Ut pharetra sit amet aliquam id diam maecenas. Quis commodo odio aenean sed adipiscing diam donec. Velit scelerisque in dictum non consectetur. Ultrices eros in cursus turpis massa. Amet volutpat consequat mauris nunc congue nisi vitae.'
}],
link: [{
rel: 'canonical',
href: 'https:\/\/8080-drunomics-lupusdecouple-fd0ilwlpax7.ws-eu84.gitpod.io\/node\/3'
}, {
rel: 'alternate',
hreflang: 'de',
href: 'https:\/\/8080-drunomics-lupusdecouple-fd0ilwlpax7.ws-eu84.gitpod.io\/de\/node\/3'
}, {
rel: 'alternate',
hreflang: 'en',
href: 'https:\/\/8080-drunomics-lupusdecouple-fd0ilwlpax7.ws-eu84.gitpod.io\/node\/3'
}]
},
content_format: 'json',
content: {
element: 'node',
type: 'page',
uid: '1',
title: 'Another page',
created: '1674823558',
body: '\u003Cp\u003ELorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Arcu dictum varius duis at consectetur. Aliquam purus sit amet luctus. Varius morbi enim nunc faucibus a pellentesque sit. Vel facilisis volutpat est velit egestas dui id ornare arcu. Ut pharetra sit amet aliquam id diam maecenas. Quis commodo odio aenean sed adipiscing diam donec. Velit scelerisque in dictum non consectetur. Ultrices eros in cursus turpis massa. Amet volutpat consequat mauris nunc congue nisi vitae. Turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet. Tempus egestas sed sed risus pretium quam. Odio eu feugiat pretium nibh ipsum. Posuere sollicitudin aliquam ultrices sagittis orci. Convallis posuere morbi leo urna molestie. Porttitor rhoncus dolor purus non enim praesent. Mi tempus imperdiet nulla malesuada.\u003C\/p\u003E'
},
page_layout: 'clear',
local_tasks: [],
}))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/addRequestContentFormat/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Module addRequestContentFormat option set to json', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3100',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
addRequestContentFormat: 'json',
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/addRequestContentFormat/markup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Module addRequestContentFormat set to markup', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3101',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
addRequestContentFormat: 'markup',
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/addRequestContentFormat/unset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Module addRequestContentFormat not set', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3102',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
},
},
port: 3102,
Expand Down
2 changes: 1 addition & 1 deletion test/addRequestFormat/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Module addRequestFormat option set to true', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3200',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
addRequestFormat: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/addRequestFormat/unset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Module addRequestFormat not set', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3201',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
},
},
port: 3201,
Expand Down
2 changes: 1 addition & 1 deletion test/basicWithoutProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Site works with serverApiProxy disabled', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3002',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
serverApiProxy: false,
},
},
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Module @nuxtjs/i18n integration works', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3004',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
serverApiProxy: true,
},
i18n: {
Expand Down
2 changes: 1 addition & 1 deletion test/i18nWithoutProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Module @nuxtjs/i18n integration works', async () => {
],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3003',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
serverApiProxy: false,
},
i18n: {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/components/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
import App from '~/app.vue'

describe('Preview routes', () => {
registerEndpoint('http://127.0.0.1:3001/api/preview/node', () => ({
registerEndpoint('http://127.0.0.1:3001/ce-api/preview/node', () => ({
content: {
element: 'node-article',
body: '<p>Some <b>example</b> body.</p>'
Expand All @@ -14,7 +14,7 @@ describe('Preview routes', () => {
metatags: { meta: [], link: [], jsonld: [] }
}))

registerEndpoint('http://127.0.0.1:3001/api/node/5/layout-preview', () => ({
registerEndpoint('http://127.0.0.1:3001/ce-api/node/5/layout-preview', () => ({
content: {
element: 'node-article',
body: '<p>Some <b>example</b> body.</p>'
Expand Down
6 changes: 3 additions & 3 deletions test/unit/fetchPageAndMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ describe('fetchPage and fetchMenu use the right API endpoints', () => {
registerEndpoint('/api/drupal-ce/test-page', () => ({
content: { title: 'Via Proxy' }
}))
registerEndpoint('http://127.0.0.1:3001/api/test-page', () => ({
registerEndpoint('http://127.0.0.1:3001/ce-api/test-page', () => ({
content: { title: 'Direct API' }
}))
registerEndpoint('/api/menu/api/menu_items/main', () => ({
items: [{ title: 'Via Proxy Menu' }]
}))
registerEndpoint('http://127.0.0.1:3001/api/api/menu_items/main', () => ({
registerEndpoint('http://127.0.0.1:3001/ce-api/api/menu_items/main', () => ({
items: [{ title: 'Direct API Menu' }]
}))
})
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('fetchPage and fetchMenu use the right API endpoints', () => {
registerEndpoint('/api/menu/fr/api/menu_items/main', () => ({
items: [{ title: 'Via Proxy Menu FR' }]
}))
registerEndpoint('http://127.0.0.1:3001/api/fr/api/menu_items/main', () => ({
registerEndpoint('http://127.0.0.1:3001/ce-api/fr/api/menu_items/main', () => ({
items: [{ title: 'Direct API Menu FR' }]
}))
})
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineVitestConfig({
modules: ['../dist/module.mjs'],
drupalCe: {
drupalBaseUrl: 'http://127.0.0.1:3001',
ceApiEndpoint: '/api',
ceApiEndpoint: '/ce-api',
}
}
}
Expand Down

0 comments on commit 855fc8f

Please sign in to comment.