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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Suppose your express site is running on localhost:3500
and all api call begins with /api
create proxy.conf.json with the content
{
"/api": {
"target": "http://localhost:3500",
"secure": false
}
}
then edit package.json
and change "start": "ng serve",
to "start": "ng serve --proxy-config proxy.conf.json"
now run the project using command npm start
.Note:- ng serve will not work
For more information find documatation here