Skip to content

Instantly share code, notes, and snippets.

@mtt87
Last active May 19, 2019 09:40
Show Gist options
  • Save mtt87/d4348511e3b2a32f051aee061fc6410b to your computer and use it in GitHub Desktop.
Save mtt87/d4348511e3b2a32f051aee061fc6410b to your computer and use it in GitHub Desktop.
Now (v2) with Gatsby + lambda node functions

Running now dev works fine for the Gatsby website and I can see it correctly at http://localhost:3000. But as soon as I browse to /api/locations it doesn't work anymore:

> GET /api/locations
> Building @now/node:api/locations/index.js
downloading user files...
installing dependencies for user's code...
installing to /var/folders/4y/mlqsnhbx4yx7kwfcg8s3b9880000gn/T/co.zeit.now/dev/workPaths/7fvnfnob/api/locations
running user script...
running "npm run now-build"

What is happening here is that the now-build step is being triggered again. The result is that the process is not working correctly and after trying to rebuild again the "gatsby" part, it crashes.

{
"version": 2,
"name": "adrenaline-box",
"alias": "adrenaline-box.now.sh",
"builds": [
{ "src": "api/**/*.js", "use": "@now/node" },
{
"src": "package.json",
"use": "@now/static-build",
"config": { "distDir": "/public" }
}
],
"routes": [
{
"src": "/api/locations",
"dest": "api/locations/index.js"
}
],
"env": {
"DATABASE_URL": "@adrenaline-database-url"
}
}
{
"scripts": {
"build": "gatsby build",
"dev": "gatsby develop",
"format": "prettier --write src/**/*.{js,jsx}",
"start": "npm run develop",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"",
"now-dev": "gatsby develop -p $PORT",
"now-build": "npm run build"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment