Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
caddyproxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
caddyproxy
Commits
0a702c99
Commit
0a702c99
authored
Feb 12, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6070eaa2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
caddyapi.go
caddy/caddyapi.go
+34
-2
No files found.
caddy/caddyapi.go
View file @
0a702c99
...
@@ -197,7 +197,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
...
@@ -197,7 +197,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
// send put request to the caddy api.
// send put request to the caddy api.
path
:=
fmt
.
Sprintf
(
"%s/config/apps/http/servers/srv0/routes/%d"
,
c
.
Url
,
0
)
path
:=
fmt
.
Sprintf
(
"%s/config/apps/http/servers/srv0/routes/%d"
,
c
.
Url
,
0
)
log
.
WithField
(
"payload"
,
payload
)
.
Debug
(
"sending payload to caddy"
)
log
.
WithField
(
"payload"
,
payload
)
.
Debug
(
"sending payload to caddy"
)
if
err
:=
c
.
p
u
t
(
path
,
[]
byte
(
payload
));
err
!=
nil
{
if
err
:=
c
.
p
os
t
(
path
,
[]
byte
(
payload
));
err
!=
nil
{
return
err
return
err
}
}
success
=
true
success
=
true
...
@@ -224,13 +224,45 @@ func (c *CaddyAPI) ForwardWebsite(param types.ForwardWebsite) error {
...
@@ -224,13 +224,45 @@ func (c *CaddyAPI) ForwardWebsite(param types.ForwardWebsite) error {
// send put request to the caddy api.
// send put request to the caddy api.
path
:=
fmt
.
Sprintf
(
"%s/config/apps/http/servers/srv0/routes/%d"
,
c
.
Url
,
0
)
path
:=
fmt
.
Sprintf
(
"%s/config/apps/http/servers/srv0/routes/%d"
,
c
.
Url
,
0
)
log
.
WithField
(
"payload"
,
payload
)
.
Debug
(
"sending payload to caddy"
)
log
.
WithField
(
"payload"
,
payload
)
.
Debug
(
"sending payload to caddy"
)
if
err
:=
c
.
p
u
t
(
path
,
[]
byte
(
payload
));
err
!=
nil
{
if
err
:=
c
.
p
os
t
(
path
,
[]
byte
(
payload
));
err
!=
nil
{
return
err
return
err
}
}
return
nil
return
nil
}
}
func
(
c
*
CaddyAPI
)
post
(
path
string
,
data
[]
byte
)
error
{
// send a get request to the Caddy API.
req
,
err
:=
http
.
NewRequest
(
"POST"
,
path
,
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"failed to create request"
)
return
err
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
resp
,
err
:=
c
.
client
.
Do
(
req
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"failed to send request"
)
return
err
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"failed to read response body"
)
return
err
}
if
resp
.
StatusCode
!=
http
.
StatusOK
{
log
.
WithFields
(
log
.
Fields
{
"status"
:
resp
.
StatusCode
,
"message"
:
string
(
body
),
})
.
Error
(
"failed to post data"
)
return
fmt
.
Errorf
(
"failed to post data"
)
}
return
nil
}
func
(
c
*
CaddyAPI
)
put
(
path
string
,
data
[]
byte
)
error
{
func
(
c
*
CaddyAPI
)
put
(
path
string
,
data
[]
byte
)
error
{
// send a get request to the Caddy API.
// send a get request to the Caddy API.
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
path
,
bytes
.
NewBuffer
(
data
))
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
path
,
bytes
.
NewBuffer
(
data
))
...
...
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