2017-02-07 11 views
2

我進口restivus使用:錯誤而instanciating Restivus 「無法找到名爲 'Restivus'」

流星加敏捷:restivus

,同時使用Restivus我遇到這個錯誤的流星啓動:

「找不到名字'Restivus'」。

雖然GET請求,但我不知道它是否會影響應用程序的行爲。

下面是使用的代碼:

if (Meteor.isServer) { 
     // Global API configuration 
     var Api = new Restivus({ 
      apiPath: 'api/', 
      prettyJson: true 
     }); 
    } 

當收到的留言我request.body和我bodyParams是空的:

Api.addRoute(':id/test', { 
     post: function() { 
      var id = this.urlParams.id; 
      console.log("Body contains : "); 
      console.log(this.bodyParams); 
      return { 
       status: 'success', 
       url : 'post test from id: '+id, 
       body : this.bodyParams 
      }; 
     } 
    }); 

有誰知道如何使這個錯誤消失,如果這是鏈接到POST身體問題?

+1

你是如何導入restivus的?使用npm還是restivus包? – Mikkel

+0

與流星添加靈活:restivus –

回答

1

如果使用流星1.4+,你可以嘗試導入Restivus到您的文件有這樣的事情:

import Restivus from 'nibmle:restivus'; 
+0

我使用流星1.6,如果我把這個導入我得到錯誤:「無法找到模塊'靈活:restivus」。 –

+0

你可以試試meteor/nimble:restivus –

0

您的代碼看起來確定。以下是我使用的僅限於服務器的文件的一些代碼:

// Global API configuration 
    var Api = new Restivus({ 
    useDefaultAuth: true, 
    prettyJson: true, 
    apiPath: 'restAPI/', 
    defaultHeaders: { 'Content-Type': 'application/json;encoding="UTF-8"' } 
    }); 

    // Generates: GET, POST on /api/items and GET, PUT, DELETE on 
    // /api/items/:id for the Items collection 
    Api.addCollection(Policy); 

也許您應該將代碼移動到服務器目錄?我在流星1.3.4上。

+0

我已經把代碼放在服務器目錄中,而且我在Meteor 1.6上。 –

+0

流星1.6?不知道這是否甚至發佈了花花公子! – Mikkel

+0

你說得對,對不起。版本是1.4.3.2 –

1

帖子正文爲空的問題是由我提出的請求造成的: 我沒有指定Content-type標頭。

一旦我指定了「Content-Type」:「application/json」它就起作用了。

雖然「無法找到'Restivus'」錯誤仍然存​​在。

相關問題