Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从post获取重定向不会导致查看更新_Node.js_Reactjs_Express_Redirect_Post - Fatal编程技术网

Node.js 从post获取重定向不会导致查看更新

Node.js 从post获取重定向不会导致查看更新,node.js,reactjs,express,redirect,post,Node.js,Reactjs,Express,Redirect,Post,我在express中有一个post路由,它是从Axios请求查询的。它的目标是简单地验证用户并将其重定向到受保护的页面。身份验证成功,但重定向不会呈现新视图。为什么res.redirect不起作用,如何获得重定向以呈现新页面 我有一个相当独特的开发环境,尝试复制生产构建: 我正在OSX Mojave 10.14.6上运行构建 我正在将我的域网站www.website.com和www.website.com重定向到/etc/hosts中的localhost 我通过https包安装了自签名SSL证

我在express中有一个post路由,它是从Axios请求查询的。它的目标是简单地验证用户并将其重定向到受保护的页面。身份验证成功,但重定向不会呈现新视图。为什么
res.redirect
不起作用,如何获得重定向以呈现新页面

我有一个相当独特的开发环境,尝试复制生产构建:

  • 我正在OSX Mojave 10.14.6上运行构建
  • 我正在将我的域网站www.website.com和www.website.com重定向到/etc/hosts中的localhost
  • 我通过https包安装了自签名SSL证书
  • 我正在运行节点v10.1.0和express
我通过调用
res.redirect(30?,/myhome')
尝试了每种类型的重定向(例如301、302和307),其中是每个请求中的最后一个数字

我猜想firefox可能有一些默认行为阻止了自签名证书的重定向。我弄乱了一些浏览器设置,但没有让它工作。我也在Safari中复制了这个问题,因为它是值得的

react中前端的Axios查询(页面中的myhome.js): 带有重定向的有问题代码位: Package.json 向远程地址发送请求至127.0.0.1:443: 请求邮件标题: post请求返回,状态代码为302

响应标题(POST): 将get请求重定向到127.0.0.1:443的受保护路由:

请求200 GET(如下所示): 请求标头: 响应标题: 浏览器发出post请求,然后执行get重定向。然而,页面从未呈现。如何重定向到其他页面

axios.post('/login', {
    username: values.username,
    password: values.password,
}).catch(
    err => {
        this.setState({
            error: {
                message: err.response.data.message,
            }
        });
    }
);
// Most route that is queried
router.post('/login', (req, res, next) => {
    const {email, username, password} = req.body;


    if((email || username) && password){
       // Either username or password can be used to login
        let creds = {
            email: email,
            password: password,
            username: username
        };
        // Database (mongodb) handles authentication 
        User.authenticate(creds, (err, usr) => {
            if (err) {
                err = new Error(error.BAD_LOGIN);
                err.level = 'warn';
                err.status = status.UNAUTHORIZED;
                return next(err); // Is passed on to error handler via next call (no error logged) 
            }else if(!usr){
                let err = Error('Incorrect username or password.');
                err.status = status.UNAUTHORIZED;
                return next(err); // No error printed
            }

            req.session.userId = usr._id;

            console.log('Success'); // Is printed to  the console

            return res.redirect('/myhome'); // The redirect that fails
        });

        return;
    }

    let err = new Error('Email and password fields required.');
    err.status = status.BAD_REQUEST;
    next(err); // No error logged
});

{
  "name": "website-front-end",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "jest",
    "dev": "nodemon server.js -vvvvv",
    "start": "nodemon server.js",
    "lint": "eslint ./ --fix",
    "purgelogs": "rm -rf ./logs"
  },
  "keywords": [],
  "author": "",
  "license": "",
  "dependencies": {
    "@zeit/next-less": "^1.0.1",
    "@zeit/next-sass": "^1.0.1",
    "antd": "^3.17.0",
    "aos": "^2.3.4",
    "axios": "^0.19.0",
    "bcrypt": "^3.0.6",
    "connect-mongo": "^3.0.0",
    "css-math": "^0.4.0",
    "email-templates": "^6.0.0",
    "express": "^4.17.1",
    "express-session": "^1.16.2",
    "http-status": "^1.3.2",
    "less": "^2.7.3",
    "less-vars-to-js": "^1.3.0",
    "lorem-ipsum": "^2.0.1",
    "mongoose": "^5.6.2",
    "next": "^8.0.4",
    "next-compose": "0.0.2",
    "node-sass": "^4.11.0",
    "nodemailer": "^6.3.0",
    "password-validator": "^4.1.1",
    "prop-types": "^15.7.2",
    "qs": "^6.7.0",
    "querystring": "^0.2.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-youtube": "^7.9.0",
    "scss": "^0.2.4",
    "units-css": "^0.4.0",
    "urlencode": "^1.1.0",
    "uuid-mongodb": "^2.1.1",
    "winston": "^3.2.1",
    "yargs": "^13.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^24.7.1",
    "babel-plugin-import": "^1.12.0",
    "babel-plugin-inline-react-svg": "^1.1.0",
    "enzyme": "^3.9.0",
    "enzyme-adapter-react-16": "^1.12.1",
    "eslint": "^5.16.0",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.12.4",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^24.7.1",
    "react-addons-test-utils": "^15.6.2",
    "react-svg-loader": "^2.1.0",
    "webpack-cli": "^3.3.6"
  }
}
Host: www.website.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://www.website.com/signin
Content-Type: application/json;charset=utf-8
Content-Length: 49
DNT: 1
Connection: keep-alive
HTTP/1.1 302 Found
X-Powered-By: Express
Location: /myhome
Vary: Accept
Content-Type: text/plain; charset=utf-8
Content-Length: 30
Set-Cookie: connect.sid=s%3AHem_Jo7jDFZ0xFz4_saY_da7USFz3VCm.9Uvt%2FW6%2BZ5Krvodm9uRoO7QdBt1snQN6vwBO5rZ3s5U; Path=/; HttpOnly
Date: Mon, 12 Aug 2019 17:34:49 GMT
Connection: keep-alive
Host: www.website.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json;charset=utf-8
Referer: https://www.website.com/signin
DNT: 1
Connection: keep-alive
Cookie: connect.sid=s%3AHem_Jo7jDFZ0xFz4_saY_da7USFz3VCm.9Uvt%2FW6%2BZ5Krvodm9uRoO7QdBt1snQN6vwBO5rZ3s5U
HTTP/1.1 200 OK
X-Powered-By: Express
Cache-Control: no-store, must-revalidate
ETag: "75c-ZfHLepOsT6dLq3dgAF6hwjkWLN4"
Content-Type: text/html; charset=utf-8
Content-Length: 1884
Date: Mon, 12 Aug 2019 17:34:50 GMT
Connection: keep-alive