Search code examples
cordovaazure-web-app-servicerequirejshandlebars.jscordova-plugins

getting error to access file of azure app service by requirejs with text plugin


I have files under platforms/browser/www in cordova browser platform and I have uploaded that file on azure kudu wwwroot folder. The App running perfectly on local machine but getting error while running on azure app service.

Error:

enter image description here

When I'm debugging it then getting the error at line no 17

define(["handlebars"], function (Handlebars) {
  Handlebars = Handlebars || this.Handlebars;
  var templateExtension = ".hbs";

  return {

    pluginBuilder: "./hbs-builder",

    // http://requirejs.org/docs/plugins.html#apiload
    load: function (name, parentRequire, onload, config) {

      // Get the template extension.
      var ext = (config.hbs && config.hbs.templateExtension ? config.hbs.templateExtension : templateExtension);

      // In browsers use the text-plugin to the load template. This way we
      // don't have to deal with ajax stuff
      parentRequire(["text!" + name + ext], function (raw) {
        // Just return the compiled template
        onload(Handlebars.compile(raw));
      });

    }

  };
});

I'm not able to understand why text plugin not access file on azure app service where as application running on local machine perfectly. Any help would be more appreciated!

Also checked this URL but not helped:

https://github.com/requirejs/text


Solution

  • I finally got the answer after some research. RequireJS Text plugin needs access some static files from wwwroot folder and for that we need Web.config file with static content as we want and rewrite rule. In my case Web.config file is given below and my site is running now perfectly.

    <?xml version="1.0" encoding="utf-8"?>
    
    <configuration>
        <system.webServer>
            <staticContent>
                <mimeMap fileExtension=".hbs" mimeType="text/css" />
            </staticContent>
            <rewrite>
                <rules>
                    <rule name="Main Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
    
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>