Reputation: 249
I am working on a Angular 4 app built from CLI, while the back end API is still under development, I have set up some json files under assets folder for http.get. Everything works well on my local, but when I deploy to IIS, in the Network tab of the dev tool, I see the 404 when trying to access the json file. The way I am setting up the URL in my code is hard coded 'assets/api/manager/model.json'. I built the project by running npm build --prod and copied over the content in dist folder. I do see the assets/api/manager/model.json file under dist after the build. I see that there are various ways of tweaking on the routes when hosting on IIS and I have tried them all (I think) but can't seem to get it to work.
Below is the http.get code
private assignTasksViewModelUrl = 'assets/api/manager/model.json';
getTaskAssignmentViewModel(): Observable<AssignTasksViewModel> {
return this.http.get(this.assignTasksViewModelUrl)
.map((response: Response) => <AssignTasksViewModel>(this.extractDate(response)))
.do(data => console.log(JSON.stringify(data)))
.catch(this.handleError);
}
Upvotes: 3
Views: 2774
Reputation: 71
Add works for me. Just a reminder the tag should be inside :
<system.webServer>
...
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
...
</system.webServer>
The other way is go to IIS Manager to add MIME Types to it.
Go to IIS Manager --> open your website --> click "Feature View" tab on the right side --> MIME Types(Double click) --> Actions: Add (right side) --> File name extension: .json, MIME Type: application/json.
Upvotes: 6
Reputation: 249
In case anyone else having the same problem. My problem was our IIS was not configured to handle .json file. By adding the following to the web.config solves the problem.
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
Upvotes: 1