【问题标题】:Adding an http redirect to a secure application in React.js在 React.js 中向安全应用程序添加 http 重定向
【发布时间】:2021-08-13 18:09:23
【问题描述】:

我已经构建了一个在 https 上运行的 react.js 应用程序。我想安排它,以便如果用户转到 url 的非安全 (http) 版本,它会被重定向到 https 而不仅仅是未找到的错误。 这是我现在拥有的代码:

                var https = require("https");
                https.createServer(httpsOptions, expressApp)
                    .listen(middle_port);
                const { createServer } = require("https");

                const handle = app.getRequestHandler();
                createServer(httpsOptions, (req, res) => {
                    const parsedUrl = parse(req.url, true);
                    handle(req, res, parsedUrl);
                 }).listen(gui_port, (err) => {
                    if (err) throw err;
                    console.log("Gui listening on " + gui_port);

                 });

【问题讨论】:

标签: reactjs https


【解决方案1】:

虽然可以通过 React 实现,但我强烈建议您通过 Nginx 或其他方式在服务器级别执行此操作,并在那里添加重定向规则。但是,如果您仍想通过 React 进行操作,请查看 react-https-redirect

【讨论】:

    猜你喜欢
    • 2018-09-20
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    相关资源
    最近更新 更多