使用create-react-app进行反应设置 BE在节点
我在heroku上部署了应用程序并且看起来都不错但是当我到达我的BE时,我得到了404(未找到)。
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var serveStatic = require('serve-static');
app = express();
app.use(bodyParser());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var port = process.env.PORT || 5000;
require('./server/routes')(app);
app.listen(port);
console.log('server started '+ port);
这是路线
module.exports = function (app) {
let apiUrlBase = "/api/v1";
app.get(`${apiUrlBase}/get-report/:_email`, (req, res) => {
const email = req.params._email;
axios.get(`https://www.beenverified.com/hk/dd/email?email=${email}`)
.then(response => {
let parserNames = utils.getNames(response.data);
let parserEmails = utils.getEmails(response.data);
let parserJobs = utils.getJobs(response.data);
let parserSocials = utils.getSocials(response.data);
let report = { "names": parserNames, "emails": parserEmails, "jobs": parserJobs, "socials": parserSocials };
res.json(report);
})
.catch(error => {
res.status(500).send('Internal Server Error');
});
})
}
答案 0 :(得分:0)
如果您要在一个Express实例中同时提供api和react应用,请确保您的express应用区分了api端点和react app端点。我遇到了类似的问题。参见Redux-Saga with babel/webpack "actions must be plain objects..." error in production but not dev