ionic运行android时未找到ionic错误404
我有一个ionic应用程序,当我向我的本地主机发出POST orGET请求时,它与ionic serve配合得很好;当我制作ionic uild android,然后运行ionic android时,它与bt配合得很好。我总是收到一个404 POST not found, 我几乎什么都试过了。 我已经添加了插件白名单并将其放入我的config.xml中ionic运行android时未找到ionic错误404,android,node.js,cors,ionic,sails.js,Android,Node.js,Cors,Ionic,Sails.js,我有一个ionic应用程序,当我向我的本地主机发出POST orGET请求时,它与ionic serve配合得很好;当我制作ionic uild android,然后运行ionic android时,它与bt配合得很好。我总是收到一个404 POST not found, 我几乎什么都试过了。 我已经添加了插件白名单并将其放入我的config.xml中 <content src="index.html"/> <access origin="*"/> <a
<content src="index.html"/>
<access origin="*"/>
<allow-intent href="*"/>
<allow-navigation href="*"/>
})
在app.js的开头,我有这个配置
angular
.module('frontend', [
'ionic', 'ionic.service.core',
'frontend.core',
'ionic.service.analytics',
//'cacheapp',
//'cachemodule',
'ionic-cache-src',
'formlyIonic',
'pascalprecht.translate',
'angularMoment',
'ionic.components',
'ngFacebook',
'translate.app',
'translate.form',
'angular-cache',
'ngCordova',
'gettext',
'module.user',
'module.gallery'
])
.constant('AccessLevels',{
anon: 0,
user: 1,
admin: 2
})
.constant('BackendConfig',{
url: "http://api-test-dev.com:1337",
//url: "http://ip_of_my_phone:1337"
//url: "10.0.2.2"
//url: "10.0.2.2:1337"
//url:"http://ip_of_my_phone"
//url:"http://ip_of_my_wifi"
//url:"http://ip_of_my_wifi:1337"
})
注释URL是我尝试的所有选项:我使用ifconfig获得它们,当我的手机出现这种情况时,我禁用了计算机上的wifi,并使用了手机的usb连接(因此ifconfig中的ip是usb0)。我还在app.js中使用端口转发尝试了url“”chrome://inspect/#devices (通过向我的设备的端口1337分配本地主机:我的计算机的1337)
. 对于我的文件app.js中列出的URL,我禁用了端口转发
但所有配置都会给出错误POST 404 not found
有什么想法吗?我想我以前遇到过这个问题 原因是当您运行
ionic-serve
或ionic-run-android-l
时,它运行的是从您的计算机托管的代码(www文件夹),而不是设备。因此,它可以直接访问localhost
。但是,当您构建它并在实际设备上运行时,其中没有托管本地主机,然后出现404notfound
这就是我解决问题的方法(仅适用于相同的Wi-fi网络)
- 获取计算机的LAN/Wi-fi IPv4(例如:
)192.168.1.2
- 将中的url替换为您的计算机IP
- 在末尾添加端口。(例如:
)http://192.168.1.2:1337
- 运行
ionic运行android
module.exports.cors = {
/***************************************************************************
* *
* Allow CORS on all routes by default? If not, you must enable CORS on a *
* per-route basis by either adding a "cors" configuration object to the *
* route config, or setting "cors:true" in the route config to use the *
* default settings below. *
* *
***************************************************************************/
allRoutes: true,
/***************************************************************************
* *
* Which domains which are allowed CORS access? This can be a *
* comma-delimited list of hosts (beginning with http:// or https://) or *
* "*" to allow all domains CORS access. *
* *
***************************************************************************/
origin: '*',
/***************************************************************************
* *
* Allow cookies to be shared for CORS requests? *
* *
***************************************************************************/
credentials: true,
/***************************************************************************
* *
* Which methods should be allowed for CORS requests? This is only used in *
* response to preflight requests (see article linked above for more info) *
* *
***************************************************************************/
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
/***************************************************************************
* *
* Which headers should be allowed for CORS requests? This is only used in *
* response to preflight requests. *
* *
***************************************************************************/
headers: 'content-type, access-control-allow-origin, authorization'
angular
.module('frontend', [
'ionic', 'ionic.service.core',
'frontend.core',
'ionic.service.analytics',
//'cacheapp',
//'cachemodule',
'ionic-cache-src',
'formlyIonic',
'pascalprecht.translate',
'angularMoment',
'ionic.components',
'ngFacebook',
'translate.app',
'translate.form',
'angular-cache',
'ngCordova',
'gettext',
'module.user',
'module.gallery'
])
.constant('AccessLevels',{
anon: 0,
user: 1,
admin: 2
})
.constant('BackendConfig',{
url: "http://api-test-dev.com:1337",
//url: "http://ip_of_my_phone:1337"
//url: "10.0.2.2"
//url: "10.0.2.2:1337"
//url:"http://ip_of_my_phone"
//url:"http://ip_of_my_wifi"
//url:"http://ip_of_my_wifi:1337"
})