Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
1fabba47
Commit
1fabba47
authored
Sep 21, 2023
by
Michael Yang
Browse files
refactor default allow origins
this should be less error prone
parent
765770ef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
+17
-15
server/routes.go
server/routes.go
+17
-15
No files found.
server/routes.go
View file @
1fabba47
...
...
@@ -499,23 +499,25 @@ func CopyModelHandler(c *gin.Context) {
}
}
func
Serve
(
ln
net
.
Listener
,
origins
[]
string
)
error
{
var
defaultAllowOrigins
=
[]
string
{
"localhost"
,
"127.0.0.1"
,
"0.0.0.0"
,
}
func
Serve
(
ln
net
.
Listener
,
allowOrigins
[]
string
)
error
{
config
:=
cors
.
DefaultConfig
()
config
.
AllowWildcard
=
true
config
.
AllowOrigins
=
append
(
origins
,
[]
string
{
"http://localhost"
,
"http://localhost:*"
,
"https://localhost"
,
"https://localhost:*"
,
"http://127.0.0.1"
,
"http://127.0.0.1:*"
,
"https://127.0.0.1"
,
"https://127.0.0.1:*"
,
"http://0.0.0.0"
,
"http://0.0.0.0:*"
,
"https://0.0.0.0"
,
"https://0.0.0.0:*"
,
}
...
)
config
.
AllowOrigins
=
allowOrigins
for
_
,
allowOrigin
:=
range
defaultAllowOrigins
{
config
.
AllowOrigins
=
append
(
config
.
AllowOrigins
,
fmt
.
Sprintf
(
"http://%s"
,
allowOrigin
),
fmt
.
Sprintf
(
"https://%s"
,
allowOrigin
),
fmt
.
Sprintf
(
"http://%s:*"
,
allowOrigin
),
fmt
.
Sprintf
(
"https://%s:*"
,
allowOrigin
),
)
}
r
:=
gin
.
Default
()
r
.
Use
(
cors
.
New
(
config
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment