簡體   English   中英

無法使用express.static提供json文件

[英]unable to serve json file with express.static

我有幾個問題:

我正在構建一個帶有角度和節點(快速)的應用程序。

1)在我的節點服務器中,我正在static_dir中提供所有靜態文件

app.use(express.static(STATIC_DIR));

插入這個目錄我有一個json文件static_Dir / courts / courts.json

我的控制如下:

squashApp.controller('CourtsController',
    function CourtsController($scope) {
    //$http.get('courts/courts.json').success(function(data) {
        $scope.courts = 'courts/courts.json';
  });

而我的html文件是:

<table class="table">
    <tr>
      <th>Hour</th>
      <th>Player 1</th>
      <th>Player 2</th>
    </tr>
    <tr>
      <td>itai</td>
      <td>asf</td>
      <td>sdf</td>
    </tr>
    <tr ng-repeat="court in courts">
      <td>{{court.hour}}</td>
      <td>{{court.player1}}</td>
      <td>{{court.player2}}</td>
    </tr>

由於某種原因,此json文件的信息未顯示在我的表格中。 是什么原因?

關於單元測試和茉莉花的另一個問題:

我的測試:

describe('controllers', function(){

  it('should create courts model', (function() {
    var scope = {},
    ctrl = new squashApp.controller.CourtsController(scope);
    expect(scope.courts.length).toBe(6)
  }));

});

但我得到一個錯誤,即沒有定義CourtsController。 為了使測試有效,應該使用什么正確的語法。

謝謝。

var path = require('path');
...
app.use(express.static(path.join(__dirname, 'public')));

/courts/courts.json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM