小编eva*_*kes的帖子

在 node.js 中尝试连接到 localhost:8080 时出现“无法获取 /”

我正在使用 node.js 作为后端服务器开发backbone.js 应用程序。该应用程序基于 twitter API。当向localhost:8080我请求时,我在浏览器中收到错误“无法 GET /”,我不知道是怎么回事。我的代码如下:

服务器.js

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

var Twit = require('twit')

var client = null;


function connectToTwitter(){
   client = new Twit({
      consumer_key:         'xxx'
    , consumer_secret:      'xxx'
    , access_token:         'xxx'
    , access_token_secret:  'xxx'
  });
}

//get the app to connect to twitter.
connectToTwitter();

var allowCrossDomain = function(req, response, next) {
response.header('Access-Control-Allow-Origin', "http://localhost");
response.header('Access-Control-Allow-Methods', 'OPTIONS, GET,PUT,POST,DELETE');
response.header('Access-Control-Allow-Headers', 'Content-Type');

if ('OPTIONS' == req.method) {
  response.send(200);
}
else {
  next();
}
}; …
Run Code Online (Sandbox Code Playgroud)

javascript node.js backbone.js

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

backbone.js ×1

javascript ×1

node.js ×1