How to serve an angular2 app in a node.js server

前端 未结 5 487
你的背包
你的背包 2021-01-01 23:41

I\'m building a web app using Angular2, to create the project I\'m using Angular2 CLI webpack. Angular2 app uses other external packages also (Eg: Firebase). In addition to

5条回答
  •  庸人自扰
    2021-01-01 23:52

    Follow the Express node server with Angular 2 CLI document to serve your application through Node.js server. The application is being served Through Node.js and a REST full API. You can design this REST as your requirements.

    E.g.

    Serve application with http://localhost:5000/app

    app.get('/app/*', function(req, res) {
        res.sendFile(path.join(__dirname, 'index.html'))
    });
    

    or

    Serve data from REST calls with http://localhost:5000/rest/contacts

    app.get('/rest/user', function(req, res) {
        res.send({
            "id": 2,
            "name": "Jhon",
        })
    });
    

提交回复
热议问题