Amazon S3 Static Website with Static JSON Data - json

I am building a really simple static website on Amazon S3 to hold my presentations. I have saved the "dynamic" data into a static JSON file on the same site and use Knockout to bind to the views.
This is working well on my local machine after adding a web.config file with the following config to allow the mime types:
<system.webServer>
<handlers>
<add name="static-json" path="*.json" verb="*" modules="StaticFileModule" resourceType="File" />
</handlers>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
However, I do not know which web server S3 is using so after I deploy there, the JSON call fails and my website looks crap because the call to the static .json file fails.
A network trace on my website at http://presentations.sukul.org/ will show that the call to Presentations.txt (I have also tried Presentations.json) will fail with a 404 error. The same setup works locally in Visual Studio debugging.
So in short, what I am asking for is whether there is a way to enable the application/json mime type so that the $.ajax call succeeds in a static website hosted on Amazon S3 callling a static .json file hosted in the same website?
Thanks in advance.

Nevermind, I was overthinking this.
The only issue I had was with case sensitivity. So /json/Presentations.txt is NOT the same as /Json/Presentations.txt. Going from a Windows to a presumably *nix environment on Amazon S3 tripped me, but diagnosing the network trace gave me clues that it was not finding the JSON file.
All working fine now after making the necessary edits.

Related

IIS cannot find .json file (404) except its name is "appconfig.json" in angular spa

i have an angular application running which fetches configurations and translations during runtime from static .json files. Once i build the application and deploy it on an IIS 10, requesting any .json file except "appconfig.json" returns a 404 error.
The funny thing is, once i name any .json file to "appconfig.json" the browser returns the result. Here are some examples:
GET .../appconfig.json -> works
GET .../config.json -> 404
GET .../config.json.txt -> works
GET .../assets/locale/translations.json -> 404
RENAME config.json to appconfig.json -> works
Obviously the IIS can handle .json files (MIME type is also set to application/json). I have absolutely no idea what i could do to solve the problem.
Maybe you have an idea?
try to add the mime type as shown below:
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
Make sure that you build the application after making changes. check iis log for the sub status code.
link:
$http.get of json file always returns 404

IIS ASP Classic redirect leads to 'invalid DOCTYPE' error

Configured IIS as Web server.
Used an URL for redirect to http://FQDN/longview/testSSO.html another web client. But it giving me the error in redirect as
http 405 method not support POST request
Then I have installed the 'ASP' using 'windows Features Turn on or off' configured the ‘ASP’ to *.html request in Handler Mappings in IIS. Now it shows error in IE browser.
invalid DOCTYPE, use valid <!DOCTYPE html>
in my opinion, posting to Html files is not possible in IIS without installing a backend language to interpret the HTML files rather than the IIS static file handler.
make sure you installed iis ASP, ISAPI Extensions, static content feature.
<configuration>
<system.webServer>
<handlers>
<add name="htm" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="None" />
</handlers>
</system.webServer>
</configuration>
and to resolve the
invalid DOCTYPE, use valid
just insert <!DOCTYPE html> in your website’s HTML page.

Azure Deployment from Visual Studio not deploying a JSON file correctly?

I've deployed my website to Azure, every single thing on the website got deployed just fine except a JSON file which contains a bunch of quotes.
I'm getting a 404 not found error in the console. I've tried redeploying, and that didn't work either.
When I go to the website I just get the 404, it clearly thinks that it's adding the file.
The PublishProfile looks like this:
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://user.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>user.scm.azurewebsites.net:123</MSDeployServiceURL>
<DeployIisAppPath>user</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$user</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
</PropertyGroup>
When I right click on my quotes.JSON file it has an option to Publish it. After I clicked the button to published it, it returned a response: "Your file(s) have been successfully published."
Going back to my site, it's still not there.
Interestingly enough I successfully deployed to another hosting service to test it out and everything works perfect - however, I cannot use the other service and have to stick to Azure.
Clearly something with Azure is being screwy and I'm not sure what it is.
Azure requires this in the Web.config to properly deploy a JSON file:
<system.webServer>
<staticContent>
<!--For Azure Deployment-->
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
This will make it blow up when you run on local so make sure to only include this in the release config.

Showing videos in azurewebsites using the video tag, files is not loading [duplicate]

I am hosting a static website on a reserved web site in Azure (It is PaaS, no access to OS/IIS). I am trying to add some .mp4 videos but when I click on the links I get
The resource you are looking for has been removed, had its name changed,
or is temporarily unavailable.
Please see example here.
If I right click on the link and try to save file I get - Failed - No file.
I am using a paid instance so don't think it is resource issue. The video files are less than 2MB. They have never worked. The site is very static.
Does anyone know how I can resolve this?
Should I be hosting MP4 files in some other way?
Thanks,
The linked SO answer worked for me conceptually, but it didn't indicate the appropriate fileExtension. My config had to instead indicate the following. (Note, for any who have this question, by default my azure website didn't have a web.config initially, so I had to add the following to a text file, save as web.config, and FTP to my webroot.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".mp4" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
There is only a single way to do this currently, and I confirmed this with the Azure team.
Add a web.config file to the root of the application wwwroot\web.config with the following contents
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="application/mp4" />
</staticContent>
</system.webServer>
</configuration>
Have you confirmed your MIME type for .MP4 is correctly configured, as asked:
Windows Azure - Serve unknown (mp4) MIME types in Windows Azure IIS storage
I got this exact same problem. The video played on the localhost but not when deployed to Azure.
ewitkows' answer is correct. The web server isn't returning the proper MIME type, so you need to add them to your web.config's <system.webServer> element.
However, I'd just like to add one more detail. When you add the code that ewitkows' answer mentions, your website might stop displaying video on localhost even though it displays correctly on Azure. If you right-click the <video> HTML element and click the View Video menu command from the context-menu, it will give you a 500 HTTP Status Code, and will display the IIS custom error page for it like so:
Observe the Config Error, Config File and Config Source sections. They tell you that IIS already has a MIME type mapping for the elements you added in the web.config.
<staticContent>
<remove fileExtension=".ogv"/>
<remove fileExtension=".webm"/>
<remove fileExtension=".mp4"/>
<mimeMap fileExtension=".ogv" mimeType="video/ogg"/>
<mimeMap fileExtension=".webm" mimeType="video/webm"/>
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
</staticContent>
So, you need to also remove the IIS ones first. Then it will work on both localhost and also on Azure.
If you're using an Azure App Service, see the answer at How to add Mime Types in ASP.NET Core
I tried the web.config route and it didn't work but editing Startup.cs did
Azure Web Apps does not support some types of media files. You could use an Azure Media Service to upload it and later refer the media file from your code.

How do you configure jetty to allow access from an external server?

I've seen this asked before, with no good answers, how do you configure jetty to allow access from an external server? I've just started messing around with solr and jetty and am using the example jetty instance that comes with solr.
solr is running fine on localhost, and I can query it from sites on the same server. However, I can't access the solr instance from another server. I've googled and read quite a bit in the last few days, but have not been able to discover what's keeping jetty from allowing non localhost access to solr.
Based on what I've read, I have tried added the following line to example/etc/jetty.xml
<Set name="Host">0.0.0.0</Set>
and still got no external response
then tried
<Set name="Host">x.x.x.x</Set>
where x.x.x.x is my server's IP address
and
<Set name="Host">host.domain.com</Set>
where host.domain.com is my server's FQDN
These both resulted in the error
java.net.BindException: Cannot assign requested address
when I started.
The start command I'm using is
sudo java -jar start.jar etc/jetty.xml
You can point me to where I can read on this or spoon feed me, I don't care. I'd just like to get past this hurdle so I can keep learning about setting up and using solr.
you should add a file called clientaccesspolicy.xml for cross domain access to your static web files directory:
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-methods="*" http-request-headers="*">
<domain uri="http://*"/>
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
you should set you static directory to jetty using this code:
ResourceHandler staticHandler = new ResourceHandler();
staticHandler.setResourceBase("static/dir");
handlers.addHandler(staticHandler);