如何在node.js的帮助下使用网站在localhost上工作
How to use a site to work on localhost with the help of node.js?
我正在学习node.js,我试图使用谷歌网页在本地主机上工作,它的菜单项将被删除,但它的搜索功能应该在本地主机和网站上一样工作。这是我尝试在localhost上使用谷歌,但在localhost中显示"Can't Get",这是一种错误还是我做错了,请指导我如何实现我想要的工作。我在XP上使用node.js版本5.9.1。
提前谢谢。
search.js
var express = require('express'),
app = express();
var bodyParser = require('body-parser');
compression = require('compression');
var NLTunnel = require('node-local-tunnel');
var options = {
remoteHost : 'http://www.google.com/',
localBase : 'http://localhost:3000'
};
NLTunnel.client(options);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(compression());
app.use(express.static('assets/'));
app.listen(3000);
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
compression = require('compression'),
http = require('http'),
server = http.createServer(app);
app.use(bodyParser());
app.use('/', express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(compression());
server.listen(3000);
试试这个。这在我的机器上工作。
我尝试过使用request和cheerio,但我只得到html页面,没有任何css或js页面(如果有),搜索功能也不起作用。这样做对吗?以及我们如何使搜索功能在本地主机上正常工作。
var httpobj = require('http');
var request = require('request');
var cheerio = require('cheerio');
var all_html;
var url = 'https://www.google.co.in/?gfe_rd=cr&ei=dVHeVuLuG-uK8QeCk6vICw'
request(url, function (error, response, html) {
var $page = cheerio.load(html);
all_html = $page("html");
});
httpobj.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(all_html + ' ');
res.end('');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
相关文章:
- 如何识别我的网站中的慢速设备
- PHP中的setcookie仅适用于localhost
- 用Javascript更改我网站上的字体大小
- 有任何可能将facebook实时信使整合到一个网站中
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 将电视直播频道从网站嵌入我的网站
- Windows 8固定的网站互动程序
- 门户网站:当地时间有多有用
- 正在删除node.js中已验证的网站
- 为什么在这个网站上不能通过JS访问元素
- 需要使用谷歌应用程序脚本列出谷歌域下的所有网站
- 为什么只有工厂在棱角分明的网站上被提及
- 从应用程序脚本检查谷歌网站访问权限
- 使用谷歌网站翻译器自动翻译网页
- 使用node.js制作网站
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- 如何在node.js的帮助下使用网站在localhost上工作
- 在网站上运行node.js,但不在localhost上运行
- 使用javascript从localhost网站播放声音
- Javascript问题,使用localhost网站运行良好,没有'无法使用计算机名