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

前端 未结 5 496
你的背包
你的背包 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:54

    Here is full back end code which is working

    const express = require('express');
    var app = express();
    var port = 9999;
    
    function getRoot(request, response) {
        response.sendFile(path.resolve('./public/angular/index.html'));
     }
    
     function getUndefined(request, response) {
         response.sendFile(path.resolve('./public/angular/index.html'));
     }
    
    
     app.use(express.static('./public/angular'));
    
     app.get('/', getRoot);
     app.get('/*', getUndefined);
    
     // Start server
     app.listen(port, function () {
        console.log('server running at port: ' + port);
    }); 
    

提交回复
热议问题