Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function createAposConfig() {
// Custom Pieces
'team-members': {},
'testimonials': {},
'landing-pages': {},

// `asset` supports the project"s webpack build for client-side assets.
'asset': {},
Expand Down
62 changes: 62 additions & 0 deletions website/modules/@apostrophecms/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* pages menu
*/

const fetch = require('node-fetch');

module.exports = {
options: {
types: [
Expand Down Expand Up @@ -30,4 +32,64 @@ module.exports = {
},
],
},
handlers(self) {
return {
'notFound': {
async checkLandingPages(req) {
// Only check if response hasn't been sent yet
if (req.res.headersSent) {
return;
}

try {
// Get the landing pages module
const landingPages = self.apos.modules['landing-pages'];
if (!landingPages) {
return;
}

// Extract slug from the path (remove leading slash)
const slug = req.url.substring(1).split('?')[0];

if (!slug) {
return;
}

// Try to find a landing page with this slug
const landingPage = await landingPages.find(req, { slug }).toObject();

if (!landingPage || !landingPage.externalUrl) {
return;
}

// TEST MODE: Just output the link
const html = `
<!DOCTYPE html>
<html>
<head>
<title>${landingPage.title}</title>
</head>
<body>
<h1>Landing Page: ${landingPage.title}</h1>
<p>Slug: ${landingPage.slug}</p>
<p>External URL: <a href="${landingPage.externalUrl}" target="_blank">${landingPage.externalUrl}</a></p>
</body>
</html>
`;

// Send the test HTML
req.res.set('Content-Type', 'text/html');
req.res.send(html);

// Mark as handled
req.notFound = false;

} catch (error) {
self.apos.util.error('Error checking landing pages:', error);
// Don't send error response, let normal 404 handle it
}
}
}
};
}
};
36 changes: 36 additions & 0 deletions website/modules/landing-pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
extend: '@apostrophecms/piece-type',
options: {
label: 'Landing Page',
pluralLabel: 'Landing Pages',
alias: 'landingPages'
},
fields: {
add: {
title: {
type: 'string',
label: 'Title',
required: true
},
slug: {
type: 'slug',
label: 'Slug',
help: 'Relative path for this landing page',
required: true,
following: 'title'
},
externalUrl: {
type: 'url',
label: 'External URL',
help: 'Full external URL for this landing page',
required: false
}
},
group: {
basics: {
label: 'Basics',
fields: ['title', 'slug', 'externalUrl']
}
}
}
};
Loading