我重新阅读了类似问题的所有答案,但是我的问题没有解决。
我的MERN应用树: 天气应用:
Procfile:
web: npm start
Package.json
"scripts": {
"build": "webpack",
"start": "webpack-dev-server --open && node server.js"
},
server.js
mongoose.connect(process.env.MONGO_URL);
// Instantiate express
const app = express();
// Initialize routes middleware
app.use('/', require('./server/routes/user'));
app.use('/data', require('./server/routes/data'))
// Use express's default error handling middleware
app.use((err, req, res, next) => {
if (res.headersSent) return next(err);
res.status(400).json({ err: err });
});
// Start the server
app.listen(process.env.PORT, '0.0.0.0', () => {
});
webpack.config开发服务器
devServer: {
port: process.env.PORT || 3000,
host: 'localhost',
disableHostCheck: true,
public: 'weather-mern.herokuapp.com',
//Be possible go back pressing the "back" button at chrome
historyApiFallback: true,
noInfo: false,
stats: 'minimal',
publicPath: publicPath,
contentBase: path.join(__dirname, publicPath),
//hotmodulereplacementeplugin
hot: true
},
在客户端/ 我有要求
如何更改API_URL的正确性?
const API_URL='http://localhost:3001'
axios({
method: 'post',
url: `${API_URL}/auth/login`,
data: formData
})