首页 > 解决方案 > 使用 ReactJS 表达不更新 get 函数

问题描述

我有一个运行良好的 express/react 应用程序,它是一个单页应用程序。我需要在服务器端对身份验证进行一些更改,但我注意到运行快速服务器我的应用程序没有提供更新的 .get 功能。关于为什么会发生这种情况的任何想法?

旧功能

app.get('/app/', (req, res) => {
    res.sendFile(path.join(__dirname, 'build', 'index.html'))
})

新功能:

app.get('/app/', async (req, res) => {
    const authorized = await checkSession(req)
    if (!authorized) {  res.redirect('/login'); return}
    res.send("OK")
})

我想我应该OK在浏览器中得到一个纯文本作为响应,但即使更改服务器端口、浏览器或任何我能想到的东西,我也会得到旧页面。任何帮助深表感谢。

标签: node.jsreactjsexpress

解决方案


删除第一个参数的尾部斜杠app.get()

app.get('/app', async (req, res) => {
    const authorized = await checkSession(req)
    if (!authorized) {  res.redirect('/login'); return}
    res.send("OK")
})

推荐阅读