3

クライアント側フレームワークとして nodeJS と angular2 を使用してアプリを作成したいと考えています。ノード プロジェクトを作成し、パブリック フォルダーに angular-cli を使用して角度付きプロジェクト全体を作成します。nodeJSにルートがあります

// api routes
app.get('/api/getSomeData', function(req, res){
    res.json({'data': 'Dummy Data'});
});

// Redirect all other routes to angular index file
app.get('*', function(req, res){
    res.sendFile(__dirname + '/public/src/index.html');
});

angulars index.html ページを提供できません。angular をビルドする必要があるかどうか、およびビルドの方法がわかりません。

4

1 に答える 1

1

I get it. After ng build command in angular root folder ( node/public ) and next line of code in nodes main file ( my is server.js ) all is good and angular is loaded as is should.

app.use(express.static(__dirname + '/public/dist'));

and node route

app.get('*', function(req, res){
    res.sendFile(__dirname + '/public/dist/index.html');
});
于 2016-05-13T13:32:13.057 に答える