http-go-server icon indicating copy to clipboard operation
http-go-server copied to clipboard

Ways to *also* serve /doc/index.html (the swagger UI) in existing server (go run internal/main.go)

Open porteusconf opened this issue 5 years ago • 1 comments

"Try it out" examples in doc/index.html defaults curl commands sent to same host and port that is serving the index.html, so same server needs to be able to handle the api as well as serving up index.html file. If there is a way to serve index.html on some port other than 8080, but have examples in index.html submitted at 8080 that might work.

If not, and we need index.html served from same port number as the apis, then I'll be trying ways to enable main.go to also serve the doc/index.html swaggerUI. Can't have net/http listening on same port as restapi, so I think it needs middleware per: http://goswagger.io/faq/faq_documenting.html#serving-swagger-ui-with-the-api-server http://goswagger.io/faq/faq_documenting.html#how-to-serve-my-ui-files

Can the swagger-UI (index.html) can be served up within the restapi server? Other approaches: https://stackoverflow.com/questions/48792295/how-to-integrate-swagger-ui-with-golang-and-goa

porteusconf avatar Jul 01 '20 17:07 porteusconf

I'm looking for something that works with go similar to this weather example for npm with swagger-tools at https://github.com/apigee-127/swagger-tools/blob/master/docs/QuickStart.md

In one terminal:

bash-3.2$ pwd
/Users/Shared/2020/api/npm/swagger-tools/examples/2.0
bash-3.2$ ls
api			controllers		node_modules		package.json
billday-readme.txt	index.js		package-lock.json
bash-3.2$ node index.js 
Your server is listening on port 3000 (http://localhost:3000) 

http://localhost:3000/api/weather?location=27278 gives weather info a zip code 27278

(http://localhost:3000/docs):) This URL will serve Swagger UI to interactively try-out the api http://localhost:3000/api-docs: This URL will serve the Swagger document (dumps the swagger.yml file contents)

porteusconf avatar Jul 02 '20 18:07 porteusconf