Why does Angular2 require CORS when loading main.js from foreign server? - iis-7

I get this error:
XMLHttpRequest cannot load http://otherwebsite.com/myapp/app/main.js.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://otherwebsite.com' is therefore not allowed access.
when referencing a main.js file in Angular2:
System.import('http://otherwebsite.com/myapp/app/main')
But no other .js files require CORS pulled from the other site.
I know how to add CORS support for Web API 2 for methods but this is not a method. I know how to add CORS support for Apache folders in .htaccess files. And with a little digging I found how to add IIS 7 CORS folder support that made this error go away.
Buy why would Angular2 need CORS for my main.js when all the other .js files loaded without CORS issues?

If the script is loaded from another domain (which even means a different IP port) than index.html was initially loaded, then the server you request a file from, needs to provide the CORS headers, otherwise the browser won't allow to fetch it.

Related

Configure nginx to serve manifest.json

How should nginx be configured in order to serve a manifest.json from the root folder of my app?
I have added an entry in mime.types:
application/x-web-app-manifest+json webapp;
and since I use json I have added a location entry in my sites-enabled configuration:
location /manifest.json {
default_type application/x-web-app-manifest+json;
}
but my manifest.json is still not served correctly.
any idea what did I miss or what should I configure differently?
Well actually my configuration above is correct, my problem was the cache on my phone ;)
Since I already had accessed my PWA before making the corrections in my nginx, my manifest.json was cached with a bad content
Clearing the Google Chrome cache on my Android phone and trying again, of course after having applied my configuration and restarted nginx solve my issue
I use nginx as part of a progressive web app and I have not changed the configuration of the server at all for the manifest file.
The requirement fro deploying it (from MDN among others) is to refer to the manifest file in your html head like this:
<link rel="manifest" href="manifest.json">
Is there some more information you can share about your problem?

vendor.js file is actually an HTML file? - Ember 2.6 on nginx

When loading my application I get the WSOD, opening the console shows an error for two JS files:
uncaught SyntaxError: Unexpected token < vendor.js
uncaught SyntaxError: Unexpected token < myapp.js
Looking at the contents of the files vendor.js and myapp.js in Chromes devtools, their contents are the contents of the dist/index.html file, so they're not the actual javascript files (i.e. dist/assets/vendor.js and dist/assets/myapp.js).
The only way I built the ember application was running the command ember build, what would the reason be for seeing an html file in devtools, and is that the actual contents of what the browser sees for the JS file?
I'm using nginx and have checked that it includes /etc/nginx/mime.types, so not sure where the problem is
Probably you have configured your webserver nginx to always send out the content of the index.html. This is necessary because of embers router.
If you visit http://example.com/myroute you want to deliver the index.html to the browser and let the ember router then render the content for the myroute route.
Probably you have configured this wrong, so nginx is always sending out the index.html, for every request, which is not correct. It should only sent out the index.html if the requested file is not present.
I hope this leads you to the right direction. This is not an ember issue, just nginx configuration.
I was experiencing the same issue, but found that when I turned the locationType option in the Ember CLI config/environment.js from 'auto' to 'hash' that my pages load correctly without any changes to my server configuration.

NGINX Rewrite Rule without access to the configuration file

In apache, the rewrite rule can be written in the configuration file or in .htaccess file. How about in nginx? Can I use url rewriting without access to the configuration file?
Unfortunately, you can't. This is one of the reasons shared hostings typically use apache or litespeed, not nginx or lighttpd.
A (very ugly) workaround would be to handle all requests with a script which would contain the rewrite rules and would serve the file/script according to the request URI (and which could be modified by a user without having root privileges). However you'd have a bad performance serving static files and you'd need to handle all the request headers by this script, which is not very practical.

Receiving IIS 500 error for static files when installed with Sitecore 7.2

Hopefully somebody can point me in the direction of a solution for this particular problem.
The Scenario (Sitecore 7.2 rev 140526)
I have a static 'index.html' file hosted in a folder (let us call it 'test') inside my Sitecore web application.
If I access the index.html file directly via a web browser, everything loads correctly.
However, if I access the directory (i.e. http://myweb.site/test/) I receive a 500 error.
The error message is binding to the default document correctly, as evidenced by the details in the error message.
UPDATE: I have been able to reproduce with a fresh 7.2 instance with the NTTData CDN Connector configuration file in place.
What I have tried already
To prevent Sitecore from serving it's 404, I updated IgnoreUrlPrefixes setting
The index.html file name is in the list of default documents for the site (and folder)
In order to bypass the ExtensionlessUrl handler for .NET and resolve a 404 error, I have re-ordered the Handler Mappings to place the StaticFile handler before the ExtensionlessUrlHandler handlers.
Running on the same IIS instance, I setup a separate site with the same files and the default document loading worked correctly.
I have verified that the folder in IIS has Anonymous Authentication enabled
I have tried providing the Everyone group with full control to the folder in NTFS permissions
I have validated that the folder and folder parents are not marked as 'Hidden'.
IIS Failed request tracing did not provide much, but I did notice the Sitecore Rewrite module changing the URL a few times in the handler pipelines to append a "?". Subsequent calls by the static module did not show any warnings or errors though.
I have reproduced with a blank Sitecore 7.2 instance by adding the NTTData CDN Connector configuration file
The error I am seeing
HTTP Error 500.0 - Internal Server Error
Module: DefaultDocumentModule
Notification: ExecuteRequestHandler
Handler: StaticFile
Error Code: 0x800703e9
Requested URL: http://myweb.site/test/index.html
Physical Path: C:\MyWebsite\test\index.html
Logon Method: Anonymous
Logon User: Anonymous
Any thoughts?
While I have not figured out why the CDN connector interferes with the loading of the static files, I have been able to resolve the issue using an approach from this answer.
Essentially, by running the subfolder as an application with a classic mode application pool and putting the static file handler mapping first, the CDN connector doesn't execute and everything works great.
I think I found the cause of this.
There is a processor that is patched just before the FilterUrlExtensions processor called CDNInterceptPipeline which attempts to convert the following via a url rewrite:
/path/to/file.ext!cf!a=1!b=2 to /path/to/file.ext?a=1&b=2.
This caused all number of problems in our solution, including the one you stated above, and for the CDN set up we're using we didn't even need it. It might be that you can safely remove it from the SitecoreCDN.config as we did.
Source: https://github.com/NTTDATA/SitecoreCDN/blob/master/Code/Pipelines/CDNInterceptPipeline.cs
I accidentally had a web.config in the folder. Deleted that. Everything worked.

IIS 7.5 doesn't run *.inc as ASP Classic

I'm setting up an ASP Classic website on Win7 x64, I have done the usual trick (Add site as Application to enable global.asa, use Classic pipeline App Pool, Enable 32-bit Applications: True, Load User Profile: False, Enable Parent Paths: True, give Everyone full access to site files, use odbc 32), and the site is up and running for *.asp files. However, I have some files named as *.inc under Includes directory, and IIS doesn't seem to be able to process them.
When I try to access http://localhost//includes/myfile.inc, I got:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
I tried to add a script map in Handler Mapping, similar to the one for *.asp: Request Path = *.inc, Executable = %windir%\system32\inetsrv\asp.dll, Invoke handler only if request is mapped to File, and in the ordered list this new mapping is on top. Now I got this error when request .inc:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Any ideas?
Why are you trying to load .inc files in the browser? This is not normal behavior. Those files are meant to be included in other files, such as the ASPs.
Blocking those files from being requested is protecting you from revealing your source code, which is what would happen if IIS did serve those files; it would just output their contents verbatum.

Resources