• Resolved zgieske

    (@zgieske)


    I have the PWA plugin set up and working just fine on my primary domain, which we’ll call domain.edu, however there is also a cloudfront domain that is used for some special purposes and I’d like to be able to install the PWA from that domain as well. How would I manually add another domain for it to work under?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    I’m not sure I understand.

    Thread Starter zgieske

    (@zgieske)

    Happy to use real links since both are public. The site https://www.vaccinesafety.edu/ has the PWA app installed and is working as intended. There is a CloudFront URL available for the same site because of how it is set up which is here: https://ditamvncmg2gy.cloudfront.net/

    I’m looking to configure that additional URL in the plugin so that it also recognizes that as a valid URL for the PWA to be installed in. Would greatly appreciate any suggestions on how to accomplish that!

    Plugin Author Weston Ruter

    (@westonruter)

    Humm, OK. Probably the reason why it is not installing is due to the web app manifest. If you look at the source of https://ditamvncmg2gy.cloudfront.net/ you’ll see:

    <link rel="manifest" >

    Most likely for that to work, the https://www.vaccinesafety.edu should be stripped from the URL in the same way as you have done for the other URLs on the page. The URL for the manifest is obtained via a call to rest_url() so you can use the rest_url filter to strip out the host, using something like this:

    add_filter( 
    	'rest_url', 
    	static function ( $url, $path ) {
    		if ( '/web-app-manifest' === $path ) {
    			$url = wp_parse_url( $url, PHP_URL_PATH );
    		}
    		return $url;
    	}, 
    	10, 
    	2 
    );

    Then, if you look at the actual contents of the web app manifest, you’ll see the start_url is as follows:

    "start_url":"https:\/\/www.vaccinesafety.edu\/"

    You’ll also likely need to rewrite that to be the URL for the CloudFront domain, using whatever logic you have in place to do so. For example:

    add_filter(
    	'web_app_manifest',
    	static function ( $manifest ) {
    		if ( is_serving_from_cloudfront() ) {
    			$manifest['start_url'] = 'https://ditamvncmg2gy.cloudfront.net/';
    		}
    		return $manifest;
    	}
    );

    Naturally you’ll need to replace is_serving_from_cloudfront() with your logic.

    Hope this helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Manually adding another URL that allows the PWA to be installed’ is closed to new replies.