cordova-httpd icon indicating copy to clipboard operation
cordova-httpd copied to clipboard

wkwebview-engine-localhost VS cordova-httpd

Open roblav96 opened this issue 8 years ago • 16 comments

Would it be possible to only use cordova-httpd and then in my config.xml set the

<content src="localhost:8080/index.html"/>

I'm going to try using both.

roblav96 avatar May 19 '16 11:05 roblav96

I would guess you should include http://

<content src="http://localhost:8080/index.html"/>

knobo avatar May 19 '16 12:05 knobo

Ah good point! :)

Also how do you get around the ios9 ATS:

App Transport Security policy requires the use of a secure connection

roblav96 avatar May 19 '16 12:05 roblav96

But I guess it will not work as the index.js file sometimes contains initiation code, that is run before http server is started.

knobo avatar May 19 '16 12:05 knobo

So far I'm having no luck lol

roblav96 avatar May 19 '16 12:05 roblav96

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://', '' )

roblav96 avatar May 19 '16 12:05 roblav96

Hi @roblav96. Did you succeed to run the webserver using config.xml settings like you describe ?

grattepoil avatar Jul 02 '16 22:07 grattepoil

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

roblav96 avatar Jul 04 '16 06:07 roblav96

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 [email protected] 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 .

grattepoil avatar Jul 04 '16 07:07 grattepoil

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.

roblav96 avatar Jul 04 '16 08:07 roblav96

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

grattepoil avatar Jul 04 '16 08:07 grattepoil

You don't need to touch anything in the config.xml file.

<content src="index.html"/>

EDIT

Are you trying to use this instead of cordova's http-server for use with WK-WebView?

roblav96 avatar Jul 04 '16 11:07 roblav96

Ok thanks.

grattepoil avatar Jul 04 '16 13:07 grattepoil

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

guyromb avatar May 26 '17 15:05 guyromb

@roblav96 I'm not using Ionic, just Cordova. Where do I place your code? Thanks!

m0nstering avatar Sep 03 '17 08:09 m0nstering

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.

sunilrawat123 avatar May 03 '18 10:05 sunilrawat123

now,it is 2019 year.anybody here?do it work?or have else resolution?

MTTTM avatar Jun 14 '19 08:06 MTTTM