"Cannot GET / " IBM Bluemix 和 twilio

"Cannot GET / " IBM Bluemix and twilio

我想创建一个通过 IBM Bluemix 使用 twilio 的应用程序,但是当我打开我的路由时收到此消息:无法获取/

我认为 app.js 代码有问题,因为我只是按照一些教程进行操作,但它们都不起作用:(

// /*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')
});

我一无所知....(顺便说一句,在 Mac OSX 上使用终端)

您没有通往 "/" 的路线,因此如果您尝试启动您的应用程序,您将收到此错误消息:

http://myapp.mybluemix.net

因为你有一个 "/message" 路由,你可以像这样访问你的应用程序:

http://myapp.mybluemix.net/message

或者创建一个新的路由来访问上面第一个 URL 的应用程序:

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