[英]How can I make PhoneGap run with express using the same port in PhoneGap desktop application?
I am facing a problem connecting to a PhoneGap desktop application in my iPad. 我在iPad上连接到PhoneGap桌面应用程序时遇到问题。
I am using express to query to a MongoDB database which uses port 3000. However, PhoneGap desktop application also uses port 3000. If I change the port of my PhoneGap desktop application, I would be able to connect to the PhoneGap desktop application in my iPad. 我正在使用express来查询使用端口3000的MongoDB数据库。但是,PhoneGap桌面应用程序也使用端口3000。如果更改了PhoneGap桌面应用程序的端口,则可以连接到iPad上的PhoneGap桌面应用程序。 But, the query to MongoDB will not work.
但是,对MongoDB的查询将不起作用。
How do I run both at the same time (being able to use in iPad)? 如何同时运行两者(能够在iPad中使用)?
App.js: App.js:
var express = require('express');
var http = require('http');
var path = require('path');
var mongoose = require('mongoose');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/view');
app.set('view engine', 'jade');
app.use(express.bodyParser()) ;
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
var server = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
I tried using this method, the result is still the same. 我尝试使用此方法,结果仍然相同。
var phonegap = require('connect-phonegap'),
express = require('express'),
app = express();
app.use(phonegap());
app.listen(3000);
please try the following code piece: 请尝试以下代码:
var server = app.listen(3000,'::1', function () {
var host = server.address().address;
var port = server.address().port;
console.log('running at http://' + host + ':' + port)
});
And try accessing the node process using the following URL: 并尝试使用以下URL访问节点进程:
http://[::1]:3000/ http:// [:: 1]:3000 /
Phonegap should be accessible on the following URL: 应该可以通过以下URL访问Phonegap:
http://localhost:3000 http://本地主机:3000
Let me know if this helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.