Nginx不会重定向Express服务器端口

时间:2019-07-17 16:03:37

标签: node.js reactjs express nginx

我已经通过react-create-app创建了该应用。然后,我发现我的应用需要联系表格并添加了快递服务器。最后,我创建了nginx配置,但是仅当我访问mydomain.com:8080时,表单才提交。在pm2上运行的server.js文件。

package.json handler 添加了package.json代理(用于create-react-app应用)

server.js

"proxy": "http://localhost:8080",

onSumbit发布方法

const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const port = process.env.PORT || 8080;


app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "build")));

app.get("/", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.listen(port, () => console.log(`server running on ${port}`));

app.post("/submit-form", (req, res) => {
  …doing staff
  res.sendStatus(200);
  res.end();
});

nginx配置

handleSubmit = event => {

      const data = {
        name: this.inputName.value,
        contact: this.inputContact.value,
        plan: this.inputPlan.value
      };

      axios.post("/submit-form", { data }, config)
      .then(
        function(request) {
          console.log(request);
        })
      .catch(function(error) {
        console.log(error);
      })
    };
  };

我正在尝试直接在mydomain.com上进行表单提交。 (也许会很有用:在域中,我有Certbot生成的ssl证书)。谢谢!

0 个答案:

没有答案