pirumpi/tiny-router

Attempt to call method 'indexOf ' (a nil value)

Closed this issue · 11 comments

When i try request http://X.X.X.X/
INFO Deploying bundle (16.77 MB)...
INFO Running script...
/app/node_modules/tiny-router/lib/router.js:167: attempt to call method 'indexOf
' (a nil value)

var router = require('tiny-router'),
    tessel = require('tessel');

var lights = { 
    green: tessel.led[0], 
    blue: tessel.led[1], 
    red: tessel.led[2],
    amber: tessel.led[3]
};

router
    .get('/', function(req, res) {
        res.send('Simple light web API');
    })
    .get('/lights', function(req, res){
        res.send(lights);
    })
    .get('/green', function(req, res){
        var state = lights.green.read();
        lights.green.write(state);
        res.send({status: state});
    })
    .get('/green/{state}', function(req, res){
        var state = parseInt(req.body.state);
        lights.green.write(state);
        res.send({status: state});
    });

router.listen(8080);

I'm checking this issue right now. But make sure to update your version of firmware for the Tessel.

@pirumpi I have the latest firmware.

I'm also having the same issue when trying to get tiny-router working with my Tessel. Maybe an update to the Tessel has caused something to stop working?

It doesn't appear to happen until a client makes a GET request to my Tessel server. So at least it is actually picking up when requests happen, just seems to be having issues with working with those requests.

It looks like this is something to do with the latest update of the Tessel firmware.

I managed to get it to work by going back a version to 0.1.24 using this command:
tessel update -b 0.1.24

I'll try downgrade my Tessel firmware.

Thanks @patcat

I created a bug for the http issue in the new version of Tessel tessel/t1-runtime#694 After getting the new runtime in the Tessel, I was not able to run a simple http Server

var http = require('http');
var srv = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('okay');
}).listen(8080);

@pirumpi 0.1.24 OK

I found the issue, the request.url is returning a Buffer and before is was returning an String. I'll push the fix in a few minutes.

Issue fixed with 7141593

Thanks! Appears to be working now with the latest Tessel firmware :)