netlify / netlify-lambda

Helps building and serving lambda functions locally and in CI environments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serve the full website

niicojs opened this issue · comments

commented

I think it would be better to:

  • server the full website (easier to test lambda functions in context)
  • server the function with the /.netlify/functions/ path)
  • parse .env to set environment variables

I did it here for personal use, I can PR it if it make sense for others.

@niicojs It makes sense for me. I'll use your fork unless/until there is an alternative.

There are many different ways people serve their app depending on the framework, setup, etc. etc. etc.

I'd suggest an approach like this https://github.com/netlify/netlify-faunadb-example/blob/master/package.json#L15-L17

Where you can use npm-run-all to run the function code + your web app in the same terminal session.

If you clone down that repo, npm install, and npm start you can see it in action

Thanks for the suggestion @DavidWells. In my specific case I'm not using react or webpack and don't want those additional dependencies just to proxy requests. I'm using browsersync for serving static files and can proxy netlify-lambda functions locally, but without native rewrite support. This makes niicojs' idea/fork useful to me.

commented

@sparkalow if you're still looking for alternatives, I've written 8eecf0d2/netlify-local to support more Netlify services locally, namely the static file server for the publish directory of netlify.toml configs. Webpack is included as a dependency but usage is completely optional.

Thanks all - i think we're gonna keep netlify-lambda small/general as possible. But @8eecf0d2 and @niicojs's approaches are interesting and i will link to you from the github. if we get more feedback like this from people i am open to reopening this