问题描述
我已经在Angular 2中构建了一个应用程序来从数据库中获取数据,并使用node/express从服务器中获取数据并将其提供给Angular客户端.当前它们都在不同的本地主机上运行.如何将它们组合成一个项目并在同一主机上运行?
I have built an app in Angular 2 to fetch data from a DB, and used node/express to fetch data from the server and serve it to the Angular client. Currently both of them are running in different local hosts. How do I combine them into a single project and run it on the same host?
推荐答案
假设您的快速站点在localhost:3500
上运行,并且所有api调用均以/api
Suppose your express site is running on localhost:3500
and all api call begins with /api
使用内容创建proxy.conf.json
create proxy.conf.json with the content
{
"/api": {
"target": "http://localhost:3500",
"secure": false
}
}
然后编辑package.json
并将"start": "ng serve",
更改为"start": "ng serve --proxy-config proxy.conf.json"
现在使用命令npm start
运行项目.注意:- ng服务将不起作用
now run the project using command npm start
.Note:- ng serve will not work
有关更多信息,请找到文档化在这里
For more information find documatation here
这篇关于如何在同一主机上运行Angular 2客户端应用程序和节点服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!