Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare compatibility(search,redirect,404) #154

Closed
Closed
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
2 changes: 1 addition & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ module.exports = function (eleventyConfig) {
}
return content;
});

eleventyConfig.addPassthroughCopy({ "src/site/cloudflare/": "/" });
eleventyConfig.addPassthroughCopy("src/site/img");
eleventyConfig.addPassthroughCopy("src/site/scripts");
eleventyConfig.addPassthroughCopy("src/site/styles/_theme.*.css");
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.1.0
22 changes: 22 additions & 0 deletions functions/api/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//cloudflare(page-function) search function
//requires wrangler.toml at root directory for module syntax
//requires .node-version >16 at root directory for cloudflare(page-function)
const searchHandler = require('../../netlify/functions/search/search.js').handler;
export async function onRequest({ request, next}) {
const response = await next();

let requestQueryParams = Object.fromEntries(new URL(request.url).searchParams);

let event = {queryStringParameters: requestQueryParams};

let searchResponse = await searchHandler(event);

const newResponse = new Response(searchResponse.body, { headers: {
'content-type': 'application/json; charset=utf-8',
response,
}
});

return newResponse;
}

11 changes: 10 additions & 1 deletion src/site/404.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

---
pagination:
size: 1
data: mypages
alias: myurl
mypages:
- 404.html
- 404/index.html
permalink: "{{ myurl }}"
---
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
Empty file added src/site/cloudflare/_redirects
Empty file.
3 changes: 3 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build.upload]
format = "modules"
main = "./worker.mjs"