Cannot GET /login

前端 未结 1 1433
忘掉有多难
忘掉有多难 2021-01-26 18:46

When I click on the login link then I go to the to /login. Which looks like this link to screenshot:

Notice the response Session not found

1条回答
  •  礼貌的吻别
    2021-01-26 18:55

    When you refresh the page at /login, the call for this URI is made on the backend and as you can see you don't support handling that route there. The code you put was correct, but you have to place it below all your route handlers. So place:

    app.route('/*').get(function(req, res) { 
        return res.sendFile(path.join(__dirname, 'public/index.html')); 
    });
    

    Below the lines:

    app.use('/', index);
    app.use('/api/auth', require('./controllers/AuthController'));
    app.use('/api/v1/', projects);
    

    Now the frontend will be loaded for every URI that isn't explicitly defined in the backend, which makes it possible for you to still use your backend API calls. Just make sure the frontend and backend don't use the same URI's.

    0 讨论(0)
提交回复
热议问题