Base solution for your next web application
Open Closed

Cross domain access for angular 2 #2919


User avatar
0
swapsword created

Hi all,

We are using ABP template(ASP.NET core 1x + Angular 2). We want to implement cross domain angular 2 application. We have two servers as localhost:4200 (default web server from ABP + Angular 2) and web server (test.de) with multipage. We want to include localhost:4200(SPA) into multipage website(test.de). We have already configurated CORS and it is working totally fine.

We have set the appPath variable as follows: var abp.appPath = "http://localhost:4200/";

Our problem is that all the files are under localhost:4200 (such as chuck.js) and the ABP template use the URL test.de to get this file. we are getting the following errors:

GET <a class="postlink" href="http://test.de:4200/sockjs-node/info?t=1491985652513">http://test.de:4200/sockjs-node/info?t=1491985652513</a> net::ERR_CONNECTION_REFUSED

GET <a class="postlink" href="http://test.de/0.chunk.js">http://test.de/0.chunk.js</a> error_handler.js:54 EXCEPTION: Uncaught (in promise): Error: Loading chunk 0 failed. Error: Loading chunk 0 failed. at HTMLScriptElement.onScriptComplete (<a class="postlink" href="http://localhost:4200/inline.bundle.js:92:33">http://localhost:4200/inline.bundle.js:92:33</a>) [angular] at HTMLScriptElement.wrapFn (<a class="postlink" href="http://localhost:4200/polyfills.bundle.js:1549:29">http://localhost:4200/polyfills.bundle.js:1549:29</a>) [angular] at Object.onInvokeTask (<a class="postlink" href="http://localhost:4200/vendor.bundle.js:36794:37">http://localhost:4200/vendor.bundle.js:36794:37</a>) [angular] at ZoneDelegate.webpackJsonp.1222.ZoneDelegate.invokeTask (<a class="postlink" href="http://localhost:4200/polyfills.bundle.js:673:36">http://localhost:4200/polyfills.bundle.js:673:36</a>) [angular] at Zone.webpackJsonp.1222.Zone.runTask (<a class="postlink" href="http://localhost:4200/polyfills.bundle.js:473:47">http://localhost:4200/polyfills.bundle.js:473:47</a>) [<root> => angular] at HTMLScriptElement.ZoneTask.invoke (<a class="postlink" href="http://localhost:4200/polyfills.bundle.js:727:38">http://localhost:4200/polyfills.bundle.js:727:38</a>) [<root>]

If you have any idea how to solve this error. In case of more info, I will be happy to provide it. Best Regards,


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    How do you include angular2 app inside your MPA, do you use an iframe ?

  • User Avatar
    0
    felixkibellus created

    Hi,

    yes the use of iframe shold be easy but this is excluded by other reasons.

    We include the angular2 app inside the MPA with :

    <body>
              <app-root></app-root>
              <script type="text/javascript" src="http://localhost:4200/inline.bundle.js"></script>
              <script type="text/javascript" src="http://localhost:4200/polyfills.bundle.js"></script>
              <script type="text/javascript" src="http://localhost:4200/scripts.bundle.js"></script>
              <script type="text/javascript" src="http://localhost:4200/styles.bundle.js"></script>
              <script type="text/javascript" src="http://localhost:4200/vendor.bundle.js"></script>
              <script type="text/javascript" src="http://localhost:4200/main.bundle.js"></script>
       </body>
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This files are generated by angular-cli and we don't have much inforation on them. It is better not to play with those files.

    You can either ask it to angular-cli team or you can move angular2 client side app into your MPA. You can use this document for that <a class="postlink" href="https://aspnetzero.com/Documents/Merge-Angular-Client-Server">https://aspnetzero.com/Documents/Merge- ... ent-Server</a>.

    It is written for AspNet Zero but mostly will work for you.

    Thanks.