我正在尝试在我的 Windows 7 机器上使用 Express.js 和Grant对 Twitter 进行 Oauth 身份验证。当我node app.js
在命令行中运行时,我得到以下信息:
问题是为什么 MADE IT HERE 也不会在控制台中输出。另外,我应该在 app.js 中我目前有“非常秘密”的地方放什么秘密?这需要成为我的消费者秘密还是任何字符串?
我正在使用 Xampp,当我想在我的浏览器 (Chrome) 中运行时,我会直接访问:http ://dummy.com:3000 /,然后我得到“此网页不可用”。如果我改为直接访问http://localhost/xampp/phptest/lions/idk/run.html,那么我会得到一个空白网页。我应该使用哪个?
这是我所有的文件:
应用程序.js
var express = require('express')
, logger = require('morgan')
, bodyParser = require('body-parser')
, cookieParser = require('cookie-parser')
, session = require('express-session');
var fs = require('fs');
var obj = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var Grant = require('grant-express')
, grant = new Grant(obj) ;
var app = express();
app.use(logger('dev'));
app.use(grant);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(cookieParser());
app.use(session({
name: 'grant', secret: 'very secret',
saveUninitialized: true, resave: true
}));
app.get('/handle_twitter_callback', function (req, res) {
console.log('MADE IT HERE');
console.log(req.query);
res.end(JSON.stringify(req.query, null, 2));
});
app.listen(3000, function() {
//document.getElementById("holder").innerHTML="GOT HERE";
console.log('Express server listening on port ' + 3000);
});
配置文件
{ "server": {
"protocol": "http",
"host": "dummy.com:3000"
},
"twitter":
{
"key": "myconsumerkey",
"secret": "myconsumersecret",
"callback": "/handle_twitter_callback"
}
}
包.json
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"bin": "./",
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.13.2",
"cookie-parser": "^1.3.5",
"errorhandler": "^1.4.1",
"express": "^4.13.1",
"express-session": "^1.11.3",
"fs": "0.0.2",
"grant-express": "^3.3.3",
"jade": "^1.11.0",
"method-override": "^2.3.4",
"morgan": "^1.6.1",
"multer": "^0.1.8",
"serve-favicon": "^2.3.0"
}
}
运行.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>run</title>
<meta name="author" content="stephen" />
<!-- Date: 2015-07-17 -->
</head>
<body>
<script src="app.js"> </script>
</body>
</html>