Skip to content

Commit

Permalink
Add basePath /api to API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
masayag committed Dec 16, 2023
1 parent 0362d5b commit 010338e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ docker-compose --env-file db.env down --remove-orphans --volumes --rmi local

### Creating a user
```bash
curl --cacert ./cert.pem -X POST https://localhost:8443/users -H "Content-Type: application/json" -d '{"description": "User description",
curl --cacert ./cert.pem -X POST https://localhost:8443/api/users -H "Content-Type: application/json" -d '{"description": "User description",
"email": "user@example.com",
"first_name": "John",
"id": 1,
Expand All @@ -72,7 +72,7 @@ curl --cacert ./cert.pem -X POST https://localhost:8443/users -H "Content-Type:

### Getting a user
```bash
curl --cacert ./cert.pem -s -X GET https://localhost:8443/users | jq
curl --cacert ./cert.pem -s -X GET https://localhost:8443/api/users | jq
[
{
"description": "User description",
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func main() {
// We can add 2 kinds of middlewares:
// - "strict" middlewares here deal in per-request generated `api` types.
// - r.Use() chi middlewares below deal in de-facto standard `http.Handler`.
strictMiddlewares := []api.StrictMiddlewareFunc{}
var strictMiddlewares []api.StrictMiddlewareFunc
strictHandler := api.NewStrictHandler(strictBloodInfoServer, strictMiddlewares)

r := chi.NewRouter()
r.Use(cors.Default().Handler) // Tell browsers cross-origin requests OK from any domain.
r.Use(middleware.OapiRequestValidator(swagger))
api.HandlerFromMux(strictHandler, r)
h := api.HandlerFromMuxWithBaseURL(strictHandler, r, "/api")
s := &http.Server{
Handler: r,
Handler: h,
Addr: net.JoinHostPort("0.0.0.0", "8443"),
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS13,
Expand Down
44 changes: 22 additions & 22 deletions pkg/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: API for managing blood donation stations and users.
version: "1.0.0"
servers:
- url: "https://localhost:8443"
- url: "https://localhost:8443/api"
description: Local development server
tags:
- name: station
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end_time=$(($(date +%s) + total_duration))

# Run the test in a loop
while [ $(date +%s) -lt $end_time ]; do
result=$(wget -q -O- --no-check-certificate https://blood-info:8443/stations | jq '. | length')
result=$(wget -q -O- --no-check-certificate https://blood-info:8443/api/stations | jq '. | length')
if [ -n "$result" ] && [ "$result" -ne 0 ]; then
echo "Test passed: There are $result stations reported."
exit 0
Expand Down

0 comments on commit 010338e

Please sign in to comment.