cordovagulpvisual-studio-cordovataco

Change host app url before build Cordova Application in Visual Studio 2015


I am using Visual Studio 2015 for develop a hosted web app using Apache Cordova by this tutorial http://taco.visualstudio.com/en-us/docs/create-a-hosted-app For open specific application url in Cordova WebView I should set this url in several places (config.xml, index.html, index.js). This url is different for develop and production environment. And before build application for production I should replace url in several places(config.xml, index.html, index.js). Is it possible to automate this task (maybe through gulp and taco-team-build module)?


Solution

  • Eventually my decision is quite simple.
    I add both developer and production url to config.xml and to index.html

    config.xml

    <allow-navigation href="http://dev/*" />
    <allow-navigation href="http://prod/*" />
    

    index.html

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: http://dev/ http://prod/ https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
    

    And in index.js I create function which return necessary url.

    function getConnectionInfo(production: boolean): ConnectionInfo
    {
        if (production)
        {
            return {
                TargetUrl: 'http://prod/',
                UsePassword: false,
                User: '',
                Password: ''
            };
        }
            return {
            TargetUrl: 'http://dev/',
            UsePassword: false,
            User: '',
            Password: ''
        };
    }
    

    If I build production application I call getConnectionInfo(true);