user3158095
user3158095

Reputation: 15

JXcore_cordova plugin nodejs android issue

using express 4.12.3 and cordova 5.0.0, and jxcore-cordova plugin:

Writing this simple segment of code doesn't work:

 var http = require('http');
 var express = require('express');
 var app = express();
 var server = http.createServer(app);
 server.listen(1337);
 app.get('/',function(req,res){
   res.sendFile(__dirname + '/public/index.html');
   res.end();
 });

The return error is:

5611-5648/com.example.hello E/jxcore-log﹕ etag@/data/data/com.example.hello/files/node_modules/express/node_modules/etag/index.js:55:1 setHeader@/data/data/com.example.hello/files/node_modules/express/node_modules/send/index.js:739:15 SendStream.prototype.send@/data/data/com.example.hello/files/node_modules/express/node_modules/send/index.js:507:3 onstat@/data/data/com.example.hello/files/node_modules/express/node_modules/send/index.js:600:5 makeCallback/<@fs.js:83:12 [email protected]:718:7 sendFile@/data/data/com.example.hello/files/node_modules/express/node_modules/send/index.js:590:3 SendStream.prototype.pipe@/data/data/com.example.hello/files/node_modules/express/node_modules/send/index.js:479:3 sendfile@/data/data/com.example.hello/files/node_modules/express/lib/response.js:1029:3 sendFile@/data/data/com.example.hello/files/node_modules/express/lib/response.js:402:3 @/data/data/com.example.hello/files/app.js:24:5 handle@/data/data/com.example.hello/files/node_modules/express/lib/router/layer.js:82:5 next@/data/data/com.example.hello/files/node_mod

However, this code works fine: using fs module:

fs.readFile(__dirname + '/public/index.html',function(err,html){
  app.get('/',function(req,res){
    res.write(html);
    res.end();
  });
});

Tested on Android Studio and eclipse on both Linux Mint and Windows 7. The plugin works fine on iOS.

Upvotes: 0

Views: 254

Answers (1)

karaxuna
karaxuna

Reputation: 26940

Try without res.end:

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

Upvotes: 0

Related Questions