Hey folks.
Iβve added a Netlify Function (myfunc
), set my functions directory in netlify.toml:
[build]
publish = "docs/.vuepress/dist"
command = "vuepress build docs"
functions = "api"
& I have it working within Netlify Dev (i.e. after running netlify dev
, I can curl http://localhost:34567/myfunc
& get a response) but when I try to fetch the endpoint from my frontend in local development, I hit issues. When I try to fetch the localhost URL (http://localhost:34567/myfunc ) in my frontend, I hit the CORS problem. When I try to fetch the URL as recommended in this guide (/.netlify/api/myfunc), I get a 404.
Any sense of what Iβm doing wrong? I looked into netlify-lambda & whether I need it but just got more confused. Any insight here would be appreciated.
Thanks,
Sam
I tried changing the URL I fetch to /.netlify/functions/myfunc
as specified in the docs but this also hits a 404. I suspect this is some issue with my local proxy? Perhaps something specific to VuePress?
Any ideas appreciated!
fool
October 28, 2019, 4:02pm
3
Could you let us know your sitename so we can take a look at whatβs deployed?
@fool thanks for replying.
Figured it out:
opened 05:38PM - 25 Oct 19 UTC
closed 02:30AM - 26 Oct 19 UTC
<!--
If you are reporting a new issue, make sure that we do not have any duplic⦠ates
already open. You can ensure this by searching the issue list for this
repository. If there is a duplicate, please close your issue and add a comment
to the existing issue instead.
If you suspect your issue is a bug, please edit your issue description to
include the BUG REPORT INFORMATION shown below. If you fail to provide this
information within 7 days, we cannot debug your issue and will close it. We
will, however, reopen it if you later provide the information.
---------------------------------------------------
BUG REPORT INFORMATION
---------------------------------------------------
Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST
-->
**- Do you want to request a *feature* or report a *bug*?**
Bug
**- What is the current behavior?**
Fetching the function URL [as specified in the docs](https://docs.netlify.com/functions/build-with-javascript/) (`/.netlify/functions/{function_name}`) returns a 404 when running `netlify dev` on my computer.
Similar to my [community post](https://community.netlify.com/t/correct-url-endpoint-for-netlify-functions-when-using-netlify-dev/4415), I've created a Netlify Function (/lamda/crowdin.js) & I've specified the build directory in my netlify.toml:
```
[build]
publish = "docs/.vuepress/dist"
command = "yarn build"
functions = "docs/.vuepress/dist/lambda"
```
This yields a working deployed version (PR [here](https://github.com/ethereum/ethereum-org-website/pull/333), deploy preview [here](https://deploy-preview-333--ethereumorg.netlify.com/languages/)) but yields a 404 in my local environment.
**- If the current behavior is a bug, please provide the steps to reproduce.**
- Clone the branch in the PR mentioned above
- Run `netlify dev`
- Access `http://localhost:8080/languages/`
**- What is the expected behavior?**
According to Netlify Dev, fetching `/.netlify/functions/{function_name}` SHOULD proxy through to the built lambda function.
**- Local Environment Information**
Paste the results of `netlify status --verbose` here
```
netlify status --verbose
βββββββββββββββββββββββ
Current Netlify User β
βββββββββββββββββββββββ
Name: Sam Richards
Teams:
Sam Richards's team: Collaborator
ethereum: Collaborator
βββββββββββββββββββββ
Environment Info β
βββββββββββββββββββββ
System:
OS: macOS 10.15
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Binaries:
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
Browsers:
Chrome: 77.0.3865.120
Safari: 13.0.2
βββββββββββββββββββββ
Netlify Site Info β
βββββββββββββββββββββ
Current site: ethereumorg
Netlify TOML: /Users/samrichards/code/ef/ethereum-org-website/netlify.toml
Admin URL: https://app.netlify.com/sites/ethereumorg
Site URL: https://ethereum.org
```
I was hitting the wrong port (8080
vs 8888
) in my browser. The netlify dev
logs are seemingly overwritten by VuePress, which instructed me to visit 8080
. You can see my open issue here with more details:
opened 02:30AM - 26 Oct 19 UTC
closed 03:28PM - 15 Apr 20 UTC
<!--
If you are reporting a new issue, make sure that we do not have any duplic⦠ates
already open. You can ensure this by searching the issue list for this
repository. If there is a duplicate, please close your issue and add a comment
to the existing issue instead.
If you suspect your issue is a bug, please edit your issue description to
include the BUG REPORT INFORMATION shown below. If you fail to provide this
information within 7 days, we cannot debug your issue and will close it. We
will, however, reopen it if you later provide the information.
---------------------------------------------------
BUG REPORT INFORMATION
---------------------------------------------------
Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST
-->
**- Do you want to request a *feature* or report a *bug*?**
Bug
**- What is the current behavior?**
Logs display port `8080` instead of `8888`
**- If the current behavior is a bug, please provide the steps to reproduce.**
Here's my terminal output:
```
~/code/ef/ethereum-org-website Β« git:(dev)
$ netlify dev
β Netlify Dev β
β Injected build setting env var: CROWDIN_API_KEY
β Starting Netlify Dev with vuepress
Waiting for localhost:8080.
β Lambda server is listening on 34567
yarn run v1.19.1
$ vuepress dev docs
..wait Extracting site metadata...
tip Apply local theme at /Users/samrichards/code/ef/ethereum-org-website/docs/.vuepress/theme...
tip Apply theme local ...
tip Apply plugin container (i.e. "vuepress-plugin-container") ...
tip Apply plugin @vuepress/register-components (i.e. "@vuepress/plugin-register-components") ...
tip Apply plugin vuepress-plugin-anonymous-31d57d61 ...
tip Apply plugin @vuepress/active-header-links (i.e. "@vuepress/plugin-active-header-links") ...
β Client βββββββββββββββββββββββββ building (40%) 43/45 modules 2 active
node_modules/punycode/punycode.js
β Client βββββββββββββββββββββββββ building (40%) 44/47 modules 3 active
node_modules/webpack/buildin/module.js
βΉ ο½’wdsο½£: Project is running at http://0.0.0.0:8080/
βΉ ο½’wdsο½£: webpack output is served from /
βΉ ο½’wdsο½£: Content not from webpack is served from /Users/samrichards/code/ef/ethereum-org-website/docs/.vuepress/public
β Client
Compiled successfully in 4.31s
βΉ ο½’wdsο½£: Project is running at http://0.0.0.0:8080/
βΉ ο½’wdsο½£: webpack output is served from /
βΉ ο½’wdsο½£: Content not from webpack is served from /Users/samrichards/code/ef/ethereum-org-website/docs/.vuepress/public
βΉ ο½’wdsο½£: 404s will fallback to /index.html
success [19:21:00] Build 27830b finished in 4310 ms!
> VuePress dev server listening at http://localhost:8080/
β Client
Compiled successfully in 179.04ms
success [19:21:01] Build b21035 finished in 180 ms! ( http://localhost:8080/ )
```
It mentions `8080` multiple times but not `8888` once.
**- What is the expected behavior?**
Can we update the logs to specify port `8888`? This will prevent issues like
https://github.com/netlify/cli/issues/583
https://github.com/netlify/cli/issues/589
**- Local Environment Information**
Paste the results of `netlify status --verbose` here
```
netlify status --verbose
βββββββββββββββββββββββ
Current Netlify User β
βββββββββββββββββββββββ
Name: Sam Richards
Teams:
Sam Richards's team: Collaborator
ethereum: Collaborator
βββββββββββββββββββββ
Environment Info β
βββββββββββββββββββββ
System:
OS: macOS 10.15
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Binaries:
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
Browsers:
Chrome: 77.0.3865.120
Safari: 13.0.2
βββββββββββββββββββββ
Netlify Site Info β
βββββββββββββββββββββ
Current site: ethereumorg
Netlify TOML: /Users/samrichards/code/ef/ethereum-org-website/netlify.toml
Admin URL: https://app.netlify.com/sites/ethereumorg
Site URL: https://ethereum.org
```
1 Like
perry
November 7, 2019, 5:02pm
5
tricky! thanks for sharing! i bet someone else needs to know about thisβ¦