Eleventy Serverless Documentation #30
Replies: 1 comment
-
@ajcwebdev This is a fantastic writeup! Thank you so much for putting this together. I don't know if and how this could help with your mental model, but We're free to mess with our |
Beta Was this translation helpful? Give feedback.
-
Eleventy Serverless Documentation
Outline
Introduction
This project utilizes Eleventy Serverless and Netlify Functions. Serverless function handlers are deployed and managed automatically by Netlify. An endpoint URL is exposed for taking requests and running JavaScript functions to return responses.
Rendering Modes
There are three different rendering modes provided by Eleventy Serverless with distinct capabilities and trade-offs. The Eleventy Serverless documentation provides the following descriptions and recommendations.
Serverless Bundler Plugin
The
EleventyServerlessBundlerPlugin
is provided toeleventyConfig
in the project's.eleventy.js
configuration file. For the sake of explanation, here is what the configuration file would look like with the other, non-serverless plugins removed.The plugin specifies:
name
serverless
functionsDir
./netlify/functions
./netlify/functions
without configuration.inputDir
./src
copy
src/themes
Serverless Function Handler
The function itself is contained in the
index.js
file inside thenetlify/functions/serverless
directory.EleventyServerless
is imported and given configuration options including theinputDir
andfunctionsDir
like ineleventyConfig
.An
event
object is passed for the URL path and query parameters. A name for the URLpath
is required, in this caseevent.path
which uses the input received through theevent
object. Dynamic Templates provide query parameters available in theeleventy.serverless.query
object that can be used to accept user input withevent.queryStringParameters
.If
try...catch
succeeds thenbody
is set toelev.render()
and a200
status code is returned. Iftry...catch
fails thenbody
is set toerror.message
and a500
status code is returned.Complete file.
Beta Was this translation helpful? Give feedback.
All reactions