如何解决将MERN app部署到Azure,一直使用“localhost”在本地运行
我正在使用 MERN 堆栈和 MongoDB 开发 Web 应用程序,并且在将应用程序部署到 Azure Web 服务时遇到问题。至此,我已经能够在本地主机上正确运行该应用程序,但我不确定为什么我的应用程序无法在 Azure 环境中运行。
来自 server.js 的片段
app.use(express.json({extended: false}));
app.use(cors());
const URI = "db_URI";
mongoose.connect(URI,{
useUnifiedTopology: true,useNewUrlParser: true,useCreateIndex: true
});
connection = mongoose.connection;
connection.once('open',() => {
console.log('db connected..!');
});
app.get("*",(req,res) => {
res.sendFile(path.resolve(__dirname,"client","build","index.html"));
});
app.use('/api/usermodel',require('./backend/routes/User'));
app.use('/projects',require('./backend/routes/projects'));
const Port = process.env.Port || 2000;
app.set('port',Port)
app.listen(Port,()=>console.log("Server started on port " + Port));
连接使用
axios.get('http://localhost:2000/projects/' + this.props.match.params.id)
我必须如何更改此连接才能在 Azure 中工作?
解决方法
无需更改您的连接使用情况。
在 .b-filter-item {
display: none
}
.b-filter-item.active {
display: block
}
上使用 <select>
<option value=""> None </option>
<option value="A"> A - 1 Match </option>
<option value="C"> C - 2 Matches </option>
<option value="F"> F - 1 Match </option>
</select>
<div class="b-filter-item" data-industry="A,B,C">
A,C
</div>
<div class="b-filter-item" data-industry="C,D,E">
C,E
</div>
<div class="b-filter-item" data-industry="F,G,H">
F,H
</div>
中间件允许服务器提供来自指定目录的静态资产。
express.static
请看看这些:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。