简体   繁体   English

将现有的nodejs服务器应用程序与现有的angular2 / 5客户端应用程序合并

[英]merge existing nodejs server app with the existing angular2/5 client app

I have built an angular5 client app and a nodejs (using express) server app working on ports 4200 and 3000 respectively. 我已经构建了一个分别在端口4200和3000上工作的angular5客户端应用程序和一个nodejs(使用express)服务器应用程序。 Now I want to merge them both in a single app as a deliverable. 现在,我想将它们作为一个交付品合并到一个应用程序中。

Will just copying the angular folder into nodejs work? 将角度文件夹复制到nodejs是否可以工作? Not sure how to go about it. 不知道如何去做。

From a code organizing perspective. 从代码组织的角度。 For development, keep each app in its own folder, something like 为了进行开发,请将每个应用都保留在自己的文件夹中,例如

nodejs
angular-app

In production, 在生产中

nodejs
  public
    angular-dist-folder

Deployment scripts can handle this for you, you should avoid doing manual copy pasting of stuff, It is important to keep code organized, it is absolutely important and vital for the success and health of any project. 部署脚本可以为您解决此问题,您应该避免手动复制粘贴内容,保持代码井井有条,这对任何项目的成功与健康绝对重要,也至关重要。

Edit: I ld like to add, modern JS projects makes use of some sort of file system watchers, Ex fs.watch . 编辑:我想补充一下,现代JS项目利用了某种文件系统监视程序,例如fs.watch Keeping apps in separate directories, prevents the unnecessary rerun of processes during development. 将应用程序保存在单独的目录中,可以防止开发过程中不必要的进程重新运行。

In your angular folder, run ng build --watch . 在您的角度文件夹中,运行ng build --watch This will build your project and create a dist folder. 这将构建您的项目并创建一个dist文件夹。 Also, it will watch for any code changes and rebuild. 此外,它将监视任何代码更改并重建。
You can copy this dist folder in your node project's public folder and make a few changes in your server.js file to integrate that. 您可以将此dist文件夹复制到节点项目的public文件夹中,并在server.js文件中进行一些更改以进行集成。

You can use nodemon server.js to look for changes in node project. 您可以使用nodemon server.js在节点项目中查找更改。

Below are the changes which I made in my server.js to make it work. 以下是我在server.js中所做的更改,以使其正常运行。

app.use(express.static(path.join(__dirname, 'public/dist')));
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'public/dist/index.html'));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM