Open roblav96 opened 8 years ago
I would guess you should include http://
<content src="http://localhost:8080/index.html"/>
Ah good point! :)
Also how do you get around the ios9 ATS:
App Transport Security policy requires the use of a secure connection
But I guess it will not work as the index.js file sometimes contains initiation code, that is run before http server is started.
So far I'm having no luck lol
This is how I got it working on iOS and Android:
cordova.plugins.CorHttpd.stopServer()
cordova.plugins.CorHttpd.startServer( {
'www_root': cordova.file.dataDirectory.replace( 'file://', '' ),
'port': 8080,
'localhost_only': true
}, function ( url ) {
this.$href = url
console.warn( 'this.$href >', this.$href )
}.bind( this ), function ( err ) {
console.error( 'startServer >', err )
} )
HERE:
cordova.file.dataDirectory.replace( 'file://', '' )
Hi @roblav96. Did you succeed to run the webserver using config.xml settings like you describe ?
Yes I did. I'm on mobile currently, so reply to this so I get a notification later and I'll post my full source
Hi rob. If you can share your source it would be very helpful. Thanks a lot. Le lun. 4 juil. 2016 à 08:24, Rob Laverty notifications@github.com a écrit :
Yes I did. I'm on mobile currently, so reply to this so I get a notification later and I'll post my full source
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/floatinghotpot/cordova-httpd/issues/47#issuecomment-230214019, or mute the thread https://github.com/notifications/unsubscribe/ACUQw1YK_iuIyVSi2ExupkKQ0Dtd8cSQks5qSKcKgaJpZM4IiLGs .
This is what you want:
document.addEventListener( 'deviceready', function () {
let www_root = cordova.file.dataDirectory.replace( 'file://', '' )
cordova.plugins.CorHttpd.startServer( {
'www_root': www_root,
'port': 8080,
'localhost_only': true
}, function ( url ) {
if ( $globals_platform == 'Android' ) {
url = url + '/'
}
$content_href = url
console.log( '$content_href >', $content_href )
}, function ( err ) {
console.error( '$content_startServer >', err )
} )
}, false )
So now you want to do something like:
let img = $content_href + 'image-file.png'
then bind the img
to src of the img tag in HTML.
where do you write this code to apply it before the app launch the webview using config.xml setting <content src="http://localhost:8080/index.html"/>
?
In the app.js file ? (i'm using ionic platform based on angularjs)
Thanks
You don't need to touch anything in the config.xml
file.
<content src="index.html"/>
Are you trying to use this instead of cordova's http-server for use with WK-WebView?
Ok thanks.
Any idea how to use cordova-httpd instead of wkwebview-engine-localhost? So I can have the localhost server for both android and iOS (wkwebview-engine-localhost is only for iOS)? @roblav96
@roblav96 I'm not using Ionic, just Cordova. Where do I place your code? Thanks!
How to replace the Origin : file:// , to something like Origin: http://192.168.10.152:8080
In case of android device.
I am using ionic v1. Please help.
now,it is 2019 year.anybody here?do it work?or have else resolution?
Would it be possible to only use cordova-httpd and then in my config.xml set the
I'm going to try using both.