1
0
Fork 0
mirror of https://github.com/GuerillaStudio/compteur-de-greve.git synced 2024-10-09 05:19:02 +00:00
compteur-de-greve/netlify/functions/serverless/index.js

58 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { EleventyServerless } = require("@11ty/eleventy");
// Explicit dependencies for the bundler from config file and global data.
// The file is generated by the Eleventy Serverless Bundler Plugin.
require("./eleventy-bundler-modules.js");
async function handler(event) {
let elev = new EleventyServerless("serverless", {
path: new URL(event.rawUrl).pathname,
singleTemplateScope: false,
query: event.multiValueQueryStringParameters || event.queryStringParameters,
functionsDir: "./netlify/functions/",
});
try {
let [page] = await elev.getOutput();
// If you want some of the data cascade available in `page.data`, use `eleventyConfig.dataFilterSelectors`.
// Read more: https://www.11ty.dev/docs/config/#data-filter-selectors
return {
statusCode: 200,
headers: {
"Content-Type": "text/html; charset=UTF-8",
},
body: page.content,
};
} catch (error) {
// Only console log for matching serverless paths
// (otherwise youll see a bunch of BrowserSync 404s for non-dynamic URLs during --serve)
if (elev.isServerlessUrl(event.path)) {
console.log("Serverless Error:", error);
}
return {
statusCode: error.httpStatusCode || 500,
body: JSON.stringify(
{
error: error.message,
},
null,
2
),
};
}
}
// Choose one:
// * Runs on each request: AWS Lambda, Netlify Function
// * Runs on first request only: Netlify On-demand Builder
// 1. Dont forget to `npm install @netlify/functions`
// 2. Also use `redirects: "netlify-toml-builders"` in your config files serverless bundler options:
// https://www.11ty.dev/docs/plugins/serverless/#bundler-options
// exports.handler = handler;
const { builder } = require("@netlify/functions");
exports.handler = builder(handler);