-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (51 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"io"
"net/http"
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
app.Use(func(c *fiber.Ctx) error {
c.Set("Access-Control-Allow-Origin", "*")
c.Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE")
c.Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
return c.Next()
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString(`
"Welcome to my project 'Ignore CORS'!"
I'm Haume!
My github: https://github.com/haume0
Project github: https://github.com/haume0/ignore-cors
---------------------------------------
In cases where you are not authorized to access the api that gives CORS error,
your local development will be able to continue without interruption.
---------------------------------------
GET: http://localhost:8080/get?url=https://www.google.com
`)
})
app.Get("/get", func(c *fiber.Ctx) error {
url := c.Query("url")
if url == "" {
return c.JSON(fiber.Map{
"message": "URL is required",
})
}
res, err := http.Get(url)
if err != nil {
return c.JSON(fiber.Map{
"message": "FETCH ERROR",
})
}
body, err := io.ReadAll(res.Body)
if err != nil {
return c.JSON(fiber.Map{
"message": "BODY READ ERROR",
})
}
return c.SendString(string(body))
})
//LISTEN ON PORT 8080
app.Listen(":8080")
}