2016-05-13 112 views
3

我想創建與nodeJS和angular2作爲客戶端框架的應用程序。我已經創建了節點項目並在公共文件夾中使用angular-cli創建了整個角度項目。我有航線的NodeJSNodeJS和角度2項目

// 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頁面。我不知道我是否必須構建角度以及如何構建。

+0

凡有JS文件?你是否也將它們重定向到'index.html'? –

+0

所有的角度文件都在nodeJS的公共文件夾中 – Nemanja

回答

1

我明白了。在角根文件夾(node/public)中生成命令並在節點主文件(my server.js)中添加下一行代碼後,所有代碼都很好,並且應該按照原樣加載角。

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

和節點路徑

app.get('*', function(req, res){ 
    res.sendFile(__dirname + '/public/dist/index.html'); 
}); 
+0

由於已經從靜態文件夾提供AngularJS,因此請移除'app.get'。 –