app.get在Heroku中未调用,但可在本地计算机中使用

时间:2018-08-24 05:37:32

标签: node.js reactjs heroku

我已经使用jwt令牌进行了电子邮件验证,问题是当我单击电子邮件链接时,路由正在本地计算机上运行,​​它成功将我重定向到登录页面,但是当我尝试在Heroku中推送它时,不起作用。当我单击电子邮件验证链接时,不会调用此路由。我猜它在reactjs和heroku中有问题。但是我的所有其他路线都可以使用,除了该路线。

server.js

app.get("/confirmation/:token", (req, res) => {
  //console.log(req.params.token);

  // Just for example:
  const PROTOCOL = keys.protocol;
  const HOST = keys.host;

  jwt.verify(req.params.token, keys.secretOrKey, function(err, decoded) {
    console.log("myconsole log"); // bar
    User.findOne({ email: decoded.email }, (err, config) => {
      console.log(config.approveReg);
      config.approveReg = true;
      config.save(err => {
        if (err) return next(err);
        // res.json({ data: config });
      });
      //  config.approveReg = true;
    });
  });

  return res.redirect(PROTOCOL + keys.dev);
});

Component.js

  componentDidMount() {
    axios
      .get("/confirmation/" + this.props.match.params.token, {})
      .then(function(response) {
         // window.location("/login");
        console.log(response);
      });
  }

App.js

import React, { Component } from "react";
import { BrowserRouter as Router, Route, Redirect } from "react-router-dom";
import { Provider } from "react-redux";
import store from "./store";

import "./App.css";
import "react-datepicker/dist/react-datepicker.css";
import Header from "./components/layout/Header";
import Register from "./components/auth/Register";
import LoginAuth from "./components/auth/LoginAuth";
import Login from "./components/auth/Login";
import Confirmation from "./components/auth/Confirmation";

class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <Router>
          <div className="App">
            <Header />
            <Route exact path="/" component={Register} />
            <Route exact path="/login" component={Login} />
            <Route exact path="/loginauth" component={LoginAuth} />
            <Route exact path="/confirmation/:token" component={Confirmation} />
          </div>
        </Router>
      </Provider>
    );
  }
}

export default App;

0 个答案:

没有答案