2016-03-31 13 views
0

Ich möchte eine App schaffen, die Twilio durch IBM Bluemix verwendet, aber ich bekomme diese Meldung, wenn ich meine Route öffnen: nicht/"Can not GET /" IBM Bluemix und Twilio

GET Kann ich denke, es ist etwas falsch in die app.js Code, weil ich einige Tutorials nur gefolgt, aber sie alle funktionieren nicht :(

// /*eslint-env node*/ 

// //------------------------------------------------------------------------------ 
// // node.js starter application for Bluemix 
// //------------------------------------------------------------------------------ 

// // This application uses express as its web server 
// // for more info, see: http://expressjs.com 
// var express = require('express'); 

// // cfenv provides access to your Cloud Foundry environment 
// // for more info, see: https://www.npmjs.com/package/cfenv 
// var cfenv = require('cfenv'); 

// // create a new express server 
// var app = express(); 

// // serve the files out of ./public as our main files 
// app.use(express.static(__dirname + '/public')); 

// // get the app environment from Cloud Foundry 
// var appEnv = cfenv.getAppEnv(); 

// // start server on the specified port and binding host 
// app.listen(appEnv.port, '0.0.0.0', function() { 

// // print a message when the server starts listening 
// console.log("server starting on " + appEnv.url); 
// }); 

var express = require('express'), 
    app = express(), 
    twilio = require('twilio'); 

var port = (process.env.VCAP_APP_PORT || 3000); 

// Pull in Twilio config from the BlueMix environment 
// The VCAP_SERVICES environment variable contains a JSON string with all your 
// Bluemix environment data 
var config = JSON.parse(process.env.VCAP_SERVICES || "{}"); 

// Loop through user-provided config info and pull out our Twilio credentials 
var twilioSid, twilioToken; 
config['user-provided'].forEach(function(service) { 
    if (service.name == 'Twilio-mario') { 
     twilioSid = service.credentials.accountSID; 
     twilioToken = service.credentials.authToken; 
    } 
}); 

app.get('/message', function (req, res) { 
    var client = new twilio.RestClient(twilioSid, twilioToken); 

    client.calls.create({ 
     url: "http://twimlets.com/message?Message%5B0%5D=Twilio%20greeting%20from%20Bluemix!&", 


    //client.sendMessage({ 
     to:'my number', 
     from:'twilio number', 
     body:'Brooooooklllllynnnn!' 
    }, function(err, message) { 
     res.send('Message sent! ID: '+message.sid); 
    }); 
}); 

var server = app.listen(port, function() { 
    console.log('Example app started') 
}); 

ich bin ratlos .... (Arbeit mit Terminal auf Mac OSX btw)

+0

Welches Tutorial folgen Sie? –

+0

https://developer.ibm.com/bluemix/2015/02/09/getting-started-twilio-ibm-bluemix/ Dieser ... und ich fand heraus. Ich muss einfach "/ Nachricht" hinter meine Route im Browser setzen. Aber ich habe so viele verschiedene Dinge ausprobiert und auf einmal funktioniert es auch so: 'app.get ('/', function (req, res) {' usw.) Also ich denke, es ist fixierte Art aus .. Gehen zu testen es ein paar mal wieder. –

Antwort

6

Sie haben keine Route zu "/", so erhalten Sie diesen Fehler, wenn Sie versuchen, Ihre Anwendung wie folgt zu starten:

http://myapp.mybluemix.net

Da Sie eine "/message" Route haben, können Sie Ihre Anwendung zugreifen wie:

http://myapp.mybluemix.net/message

oder eine neue Route erstellen die App mit der ersten URL für den Zugriff über:

app.get('/', function (req, res) { 
// your code here 
}); 
+0

Vielen Dank! ^^ –

+0

das Seltsame ist aber, dass ich meinen ersten Code ausprobiert habe, wie Sie auch nur mit dem '/' vorgeschlagen haben, aber selbst dann würde es nicht funktionieren. Und dann, wenn ich es online poste, funktioniert es plötzlich wie Magie. Es gibt jedoch noch einige Probleme mit Twilio. –