Skip to content

Commit

Permalink
fix: disable CORS for API
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Feb 6, 2024
1 parent e65e137 commit 6d4a3cb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .bruno/Parse Template with Structures.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: Parse Template with Structures
type: http
seq: 2
}

post {
url: {{ API_URL }}/parse
body: json
auth: none
}

body:json {
{
"template": "structures:\n person:\n - name: Name\n type: text\n description: Name of the person\n - name: Admin\n type: boolean\n description: Is the person an admin\nvariables:\n- name: Users\n type: person[]\n value:\n - Admin: true\n Name: Marvin\n - Admin: false\n Name: Test\n - Admin: false\n Name: Test2\n - Admin: true\n Name: Test3\ntemplate: \"You have added the following users:\n\{{ range .Users }}\n- \{{ .Name }} is an admin: \{{ .Admin }}\n\{{ end }}\""
}
}
2 changes: 1 addition & 1 deletion .bruno/Parse Template.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

post {
url: http://127.0.0.1:8080/api/v1/parse
url: {{ API_URL }}/parse
body: json
auth: none
}
Expand Down
3 changes: 3 additions & 0 deletions .bruno/environments/local.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
API_URL: http://localhost:8080/api/v1
}
3 changes: 3 additions & 0 deletions .bruno/environments/prod.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
API_URL: https://api.gttp.dev/api/v1
}
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ var rootCmd = &cobra.Command{
pterm.DefaultSection.Println("Debug Information")
pterm.DefaultSection.WithLevel(2).Println("Template")
pterm.Printfln("%#v", tmpl)
pterm.DefaultSection.WithLevel(2).Println("Parsed Template YAML")
y, err := tmpl.ToYAML()
if err != nil {
return err
}
pterm.Printfln("%s", y)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gttp-cli/gttp/pkg/model"
"github.com/gttp-cli/gttp/pkg/parser"
Expand All @@ -24,6 +25,7 @@ var serveCmd = &cobra.Command{
app := fiber.New()

app.Use(logger.New())
app.Use(cors.New())

app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(map[string]string{
Expand Down

0 comments on commit 6d4a3cb

Please sign in to comment.