corylanou / tns-restful-json-api

This is the code repository that goes along with the "TheNewStack" article for RESTful JSON API post

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server is not responding when I try to retrieve document info from curl

Starli0n opened this issue · comments

Hi,

First the server is answering correctly when I do that:

>curl -i "http://localhost:8080"
HTTP/1.1 200 OK
Date: Wed, 23 Sep 2015 10:37:26 GMT
Content-Length: 9
Content-Type: text/plain; charset=utf-8

Welcome!

But when I try to get only the document info, I have that:

>curl -I "http://localhost:8080"
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Wed, 23 Sep 2015 10:36:50 GMT
Content-Length: 19

-I, --head Show document info only

It seems that the request is not even rooted. My aim is to enable CORS Support on the server side to use swagger.

https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support

I am expected this kind of response

>curl -I "http://localhost:8080"
HTTP/1.1 200 OK
Date: Sat, 31 Jan 2015 23:05:44 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
Content-Type: application/json
Content-Length: 0

I do not know what to do in the code to achieve this. Do you have any idea ?

Thanks

Actually, it seems that adding this line solve the issue:

w.Header().Set("Access-Control-Allow-Origin", "*")