Skip to content

Instantly share code, notes, and snippets.

@robdodson
Created June 29, 2021 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robdodson/e223a02a02859d28d555229cd9a73245 to your computer and use it in GitHub Desktop.
Save robdodson/e223a02a02859d28d555229cd9a73245 to your computer and use it in GitHub Desktop.
module.exports = function (config) {
config.addPlugin(EleventyServerlessBundlerPlugin, {
name: 'possum', // The serverless function name from your permalink object
functionsDir: './functions/',
});
return {
dir: {
input: 'src/site/content/', // we use a string path with the forward slash since windows doesn't like the paths generated from path.join
output: 'dist',
data: '../_data',
includes: '../_includes',
},
templateFormats: ['njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
// Because eleventy's passthroughFileCopy does not work with permalinks
// we need to manually copy assets ourselves using gulp.
// https://github.com/11ty/eleventy/issues/379
passthroughFileCopy: false,
};
};
{
"hosting": {
"public": "dist",
"rewrites": [{
"source": "/possum",
"function": "possum"
}]
},
"emulators": {
"hosting": {
"port": 8080
}
}
}
// /functions/index.js
const possum = require('./possum');
exports.possum = possum.possum;
// /functions/possum/index.js
const functions = require('firebase-functions');
const {EleventyServerless} = require('@11ty/eleventy');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
exports.possum = functions.https.onRequest(async (request, response) => {
functions.logger.info('Hello logs!', {structuredData: true});
// return response.send(`You requested path: ${request.path}`);
const elev = new EleventyServerless('serverless', {
path: request.path, // required, the URL path
});
try {
// returns the HTML for the Eleventy template that matches to the URL
const html = await elev.render();
return response.send(html);
} catch (e) {
return response.status(500).send(JSON.stringify({error: e.message}));
}
});
---
layout: default
title: About
permalink:
possum: /about/
---
It's our about page!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment