【问题标题】:Error: No default engine was specified and no extension was provided. at new View -- node-push server错误:没有指定默认引擎,也没有提供扩展。在新视图——节点推送服务器
【发布时间】:2015-02-23 03:03:22
【问题描述】:

我正在使用来自here 的节点推送服务器

我能够成功启动服务器。下面是我的配置文件

{
"webPort": 8000,

"mongodbUrl": "mongo URL",

"gcm": {
    "apiKey": "API KEY"
},

"apn": {
    "connection": {
        "gateway": "gateway.sandbox.push.apple.com",
        "cert": "/path/to/cert.pem",
        "key": "/path/to/key.pem"
    },
    "feedback": {
        "address": "feedback.sandbox.push.apple.com",
        "cert": "/path/to/cert.pem",
        "key": "/path/to/key.pem",
        "interval": 43200,
        "batchFeedback": true
    }
}

}

以下是我的服务

var express = require('express');
var bodyParser = require('body-parser');
var app = express();

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.get('/sendTestGCM',function(request,response){
var querystring = require('querystring');
var http = require('http');//importing http

var registrationIds = [];
registrationIds.push('key here');
var gcm_android = querystring.stringify({//message to be sent
    "users": registrationIds,
    "android": {
        "data": {
            "message": "Test Message with Node-push server package"
        }
    },
    "type":"android"
});
var options = { //URL information 
        host: 'localhost',
        path: '/send',
        port: '8000',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': gcm_android.length
        }
};

var post_request = http.request(options,function(res){//Post Request
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('Response: ' + chunk);
        console.log("status code"+res.statusCode);
        response.end(""+chunk);
    });
});
post_request.write(gcm_android);
post_request.end();
});
app.listen("port");

当我测试此服务时,它抛出异常为“错误:未指定默认引擎且未提供扩展。”。

请任何人告诉我这样做的原因。

提前致谢。

【问题讨论】:

    标签: node.js express push


    【解决方案1】:

    尝试将您的选项对象更改为:

    var options = { //URL information 
            "host": "localhost",
            "path": "/send",
            "port": "8000",
            "method": "POST",
            "headers": {
                'Content-Type': 'application/json',
                'Content-Length': gcm_android.length
            }
    };
    

    属性名称必须是(带引号的)字符串才能成为 JSON 对象。 来自this answer

    JSON 规范规定使用引号以使其 实际上是JSON。如果你不使用引号,它可能是一个有效的对象 Javascript 中的文字,但它不是 JSON。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 2020-10-24
      • 1970-01-01
      相关资源
      最近更新 更多