Serverless and Firebase Functions.

7
open
robdodson
robdodson
Posted 10 months ago

Serverless and Firebase Functions. #1866

Describe the bug I'm trying to get eleventy serverless working with firebase functions. I think I've set everything up correctly, but when I visit my function I get a Node error saying that it can't find eleventy-serverless-map.json.

To Reproduce Steps to reproduce the behavior:

I put together a gist to show my structure: https://gist.github.com/robdodson/e223a02a02859d28d555229cd9a73245

Expected behavior A clear and concise description of what you expected to happen.

When I visit /possum/ I shouldn't see an error.

Actual behavior I get the following error

Cannot find module '/Users/…/functions/eleventy-serverless-map.json

Environment:

  • OS and Version: macOS
  • Eleventy Version: 1.0.0-canary.38
zachleat
zachleat
Created 10 months ago

This is as far as I got and the error message I’d expect to see on localhost right now

https://stackblitz.com/edit/node-txhs9w?devtoolsheight=33&file=.eleventy.js

image

zachleat
zachleat
Created 10 months ago

The localhost experience (right now) expects a handler function in the possum/index.js file. That’s the convention on the serverless hosts I’ve used, but I’m open to extending it!

robdodson
robdodson
Created 10 months ago

oh it looks like the stackblitz project is gone (or maybe it's private?)

In my code I did have a handler function in functions/possum/index.js. Unfortunately github gists don't let me show subdirectories so I tried to add the directory paths as comments at the top of the files.

zachleat
zachleat
Created 10 months ago

Ah sorry about that! I renamed it https://stackblitz.com/edit/robs-firebase-test

robdodson
robdodson
Created 10 months ago

The localhost experience (right now) expects a handler function in the possum/index.js file.

Oh, so the function literally needs to be named exports.handler ?

robdodson
robdodson
Created 10 months ago

oh snaaaaap! I got it working. I'll put together an example repo to share.

image

robdodson
robdodson
Created 10 months ago

Here's a repo: https://github.com/robdodson/eleventy-serverless-firebase

I did find one issue though, the _data directory does not seem to work. It works when I do a static build, but not when I let the function render it. I can see that the _data directory is being copied over to the right place, so I'm not sure what's up.

image