简体   繁体   English

如何使用PhoneGap桌面应用程序中的相同端口使PhoneGap与Express一起运行?

[英]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.

相关问题 如何在同一端口上运行Express和geddy应用程序? - How to run express and geddy apps on the same port? Express 和 React 在同一端口上运行 - 我如何使用路由? - Express and React running on same port - how can I use Routing? 使用node-express运行Phonegap applicaton - Run Phonegap applicaton with node-express 如何使用Node EJS将Web应用程序转换为具有相同功能的桌面应用程序 - How I can convert my web application to desktop application with same functionality using Node EJS Windows下的“ phonegap run android” phonegap 3无法构建项目 - “phonegap run android” phonegap 3 under windows can't build a project 如何在端口80上运行环回应用程序 - How can I run loopback application on port 80 PhoneGap:phonegap运行android时出错 - PhoneGap: Error on phonegap run android 如何使用第二节点服务器运行独立的express.js应用程序? - How can I run an independent express.js application using a 2nd node server? 如何使用pm2使express.js在端口(8080)上仅运行一个实例,而在第二实例上使用另一个端口(8081) - How to make express.js using pm2 run only one instance on port (8080) and on second instance use another port (8081) 你如何在同一个端口上运行express和socket.io - How do you run express and socket.io on the same port
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM