Redirects not going to index.html

New to Netlify, and I am trying to get the local server to load the index.html file.

My netlify.toml file looks like this:

[dev]
    command = "npm run serve"
    functions = "lambda"
    publish = "src/"

[build]
    functions = "lambda"
    publish = "src/"

# The following redirect is intended for use with most SPAs that handle
# routing internally.
[[redirects]]
  from = "/*"
  to = "index.html"
  status = 200

[[headers]]
  # Define which paths this specific [[headers]] block will cover.
  for = "/*"
    [headers.values]
    Access-Control-Allow-Origin = "*"

I also tried putting in a _redirects file with

   /* /index.html 200

If I got to http://localhost:9000/ I get the message “You have requested the root of http://localhost:9000. This is likely a mistake. netlify-lambda serves functions at http://localhost:9000/.netlify/functions/your-function-name; please fix your code.”

How do I get the root to redirect to index.html?

Hello @tyl330915, welcome to the community!

Can you provide more information on how you are trying to run your site locally? Netlify-lambda will only host your functions and nothing else. You’ll need at least the netlify-cli (cli/dev.md at main · netlify/cli · GitHub) to test your site locally.

I’m following the tutorial here: Netlify-faunadb-example
It allows me to run on a local server, but I am confused on how to properly format the output.

Hey @tyl330915 :wave:t2:

Could you share the output of your terminal once running npm start? The start command defined in the project you linked to indeed does run netlify dev but I’m curious why you’re trying to hit port 9000

Or are you kicking everything off by running netlify dev yourself? In which case, your [dev]=>command is different from the one in the tutorial you linked to :thinking:


Jon

Took me a little while, but it turns out port 9000 is used by netlify-lambda

npm run start results in

npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DellDesk\AppData\Roaming\npm-cache\_logs\2020-08-11T12_35_04_995Z-debug.log

Let’s take a couple of steps back here.

What command are you using to start your local development process? And what is the full output of that command, if you don’t mind sharing? I think that’ll help explain a lot of the trouble you’re seeing :slight_smile:


Jon

I am using “npm run serve”:

C:\Users\DellDesk\Desktop\CRUD> npm run serve

> crud@1.0.0 serve C:\Users\DellDesk\Desktop\CRUD
> netlify-lambda serve ./src --config ./configs/webpack.functions.js

netlify-lambda: Starting server
Hash: 1032ae2d1d487321897b
Version: webpack 4.43.0
Time: 890ms
Built at: 08/11/2020 9:27:22 AM
   Asset      Size  Chunks             Chunk Names

customers.js   283 KiB       0  [emitted]  customers
hello.js  1.06 KiB       1  [emitted]  hello
Entrypoint customers = customers.js
Entrypoint hello = hello.js
 [1] external "fs" 42 bytes {0} [built]
 [3] ../node_modules/dotenv/lib/main.js 2.93 KiB {0} [built]
 [4] external "path" 42 bytes {0} [built]
 [5] ../node_modules/faunadb/index.js 596 bytes {0} [built]
 [7] ../node_modules/faunadb/src/errors.js 5.74 KiB {0} [built]
 [12] ../node_modules/faunadb/src/query.js 65 KiB {0} [built]
 [13] ../node_modules/faunadb/src/Expr.js 2.31 KiB {0} [built]
 [39] ./customers.js 2.3 KiB {0} [built]
 [40] ./customers/read-all.js 2.21 KiB {0} [built]
 [91] ./customers/read.js 643 bytes {0} [built]
 [7] ../node_modules/faunadb/src/errors.js 5.74 KiB {0} [built]
 [8] ../node_modules/faunadb/src/values.js 8.76 KiB {0} [built]
[12] ../node_modules/faunadb/src/query.js 65 KiB {0} [built]
[13] ../node_modules/faunadb/src/Expr.js 2.31 KiB {0} [built]
[39] ./customers.js 2.3 KiB {0} [built]
[40] ./customers/read-all.js 2.21 KiB {0} [built]
[91] ./customers/read.js 643 bytes {0} [built]
[92] ./customers/create.js 998 bytes {0} [built]
[93] ./customers/update.js 1000 bytes {0} [built]
[94] ./customers/delete.js 676 bytes {0} [built]
[95] ./hello.js 263 bytes {1} [built]
   + 81 hidden modules
Lambda server is listening on 9000

If I then go to http://localhost:9000/.netlify/functions/customers I get the unformatted JSON output, as I do for https://echo-dog.netlify.app/.netlify/functions/customers

Okay, awesome. I think I understand where you’re coming from. The short story is that you’re going to want to be running netlify dev as the command to kick off your local development process, not npm run serve. I think the tutorial you’re following is geared to have you run netlify dev locally too, but your code differs from the tutorial in some ways there.

I’d highly recommend reading through this document to get a better understanding of what it means to run Netlify locally. I think it’ll help you better understand how to get things running smoothly :slight_smile:


Jon

Great! I will try that. I am excited about the netlify/faunadb possibilities, but just trying to get used to the idea of how to use it.