How to separate the frontend routing from backend endpoints?

Viewed 23

I have an express server which handle some routes

/users/login
/users/register 
/orders/add

and so on..

serving a static files, in the default route "/"

so, if user navigated to domain.com for example

it will navigate to that static files

these static files are a react frontend app

the default url "/" will navigate to a login page

and "/dashboard" will navigate to another page

what actually happen, is there's kind of conflict between the backend and frontend routes

for example

if user navigated to "/dashboard"

the expected result is to navigate him to the frontend page

what actual happen is "the backend handle that route not the frontend" and simply return : "I don't have that route (404)

What was in my mind is to navigate any not handled route to the frontend

using that code

  app.get('*', async function (request, reply) {
    return reply.sendFile('index.html')
  })

however, not solved my problem

0 Answers
Related