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
2e93fa3a
Commit
2e93fa3a
authored
Oct 15, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support more master domain
parent
c335710a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
caddyapi.go
caddy/caddyapi.go
+31
-4
run.go
command/run/run.go
+1
-1
No files found.
caddy/caddyapi.go
View file @
2e93fa3a
...
...
@@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"text/template"
"time"
)
...
...
@@ -17,11 +18,17 @@ import (
type
CaddyAPI
struct
{
Url
string
// URL of the Caddy API
RootDir
string
// Root directory of the Caddy to store website files and .caddy files.
MasterDomain
string
MasterDomain
map
[
string
]
bool
client
*
http
.
Client
}
func
NewCaddyAPI
(
url
string
,
root
string
,
master
string
)
*
CaddyAPI
{
func
NewCaddyAPI
(
url
string
,
root
string
,
masterList
string
)
*
CaddyAPI
{
master
:=
make
(
map
[
string
]
bool
)
list
:=
strings
.
Split
(
masterList
,
","
)
for
_
,
domain
:=
range
list
{
master
[
strings
.
ToLower
(
domain
)]
=
true
}
return
&
CaddyAPI
{
Url
:
url
,
RootDir
:
root
,
client
:
&
http
.
Client
{},
MasterDomain
:
master
}
}
...
...
@@ -128,7 +135,22 @@ func pathExist(path string) bool {
return
true
}
func
extractMasterDomain
(
domain
string
)
(
string
,
error
)
{
parts
:=
strings
.
Split
(
domain
,
"."
)
if
len
(
parts
)
<
2
{
return
domain
,
nil
}
return
strings
.
ToLower
(
strings
.
Join
(
parts
[
len
(
parts
)
-
2
:
],
"."
)),
nil
}
func
(
c
*
CaddyAPI
)
CreateWebsite
(
domain
string
,
resource
string
)
error
{
// check domain is in masterDomain list.
masterDomain
,
err
:=
extractMasterDomain
(
domain
)
if
err
!=
nil
||
!
c
.
MasterDomain
[
masterDomain
]
{
return
fmt
.
Errorf
(
"domain %s is not support on this service"
,
domain
)
}
// unzip resource to the website root directory.
websiteRoot
:=
filepath
.
Join
(
c
.
RootDir
,
"websites"
,
domain
)
rollback
:=
false
...
...
@@ -162,7 +184,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
return
err
}
// create caddyfile.
if
err
:=
c
.
newWebsiteCaddyFile
(
domain
,
websiteRoot
,
c
.
M
asterDomain
);
err
!=
nil
{
if
err
:=
c
.
newWebsiteCaddyFile
(
domain
,
websiteRoot
,
m
asterDomain
);
err
!=
nil
{
return
err
}
...
...
@@ -183,8 +205,13 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
}
func
(
c
*
CaddyAPI
)
ForwardWebsite
(
param
types
.
ForwardWebsite
)
error
{
// check domain is in masterDomain list.
masterDomain
,
err
:=
extractMasterDomain
(
param
.
Domain
)
if
err
!=
nil
||
!
c
.
MasterDomain
[
masterDomain
]
{
return
fmt
.
Errorf
(
"domain %s is not support on this service"
,
param
.
Domain
)
}
// create caddyfile.
if
err
:=
c
.
newForwardCaddyFile
(
param
.
Domain
,
param
.
Target
,
c
.
M
asterDomain
);
err
!=
nil
{
if
err
:=
c
.
newForwardCaddyFile
(
param
.
Domain
,
param
.
Target
,
m
asterDomain
);
err
!=
nil
{
return
err
}
...
...
command/run/run.go
View file @
2e93fa3a
...
...
@@ -86,7 +86,7 @@ func setFlags(cmd *cobra.Command) {
&
params
.
masterDomain
,
masterDomainFlag
,
""
,
"master domain"
,
"master domain
, if you need more than one, use ',' to split
"
,
)
}
...
...
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