1. Caddy version (caddy version
):
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
2. How I run Caddy:
via systemd
a. System environment:
Ubuntu 18.04
b. Command:
none - auto-started
c. Service/unit/compose file:
n/a
d. My complete Caddyfile or JSON config:
{
"apps":{
"http":{
"servers":{
"srv0":{
"automatic_https":{
"disable":true
},
"listen":[
":80"
],
"routes":[
{
"group":"group1",
"handle":[
{
"handler":"vars",
"root":"/opt/ivt/photography"
}
],
"match":[
{
"path":[
"/files/*"
]
}
]
},
{
"group":"group1",
"handle":[
{
"handler":"vars",
"root":"/opt/ivt/apps/6.0.0/packages/client/spa"
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/console_socket",
"replace":"/console/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3001"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/console_socket/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/web_app_socket",
"replace":"/web/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3001"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/web_app_socket/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/liveview",
"replace":"/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3004"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/liveview/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/weather",
"replace":"/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3010"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/weather/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/archive",
"replace":"/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3003"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/archive/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/alarms",
"replace":"/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3002"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/alarms/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"rewrite",
"uri_substring":[
{
"find":"/ptz",
"replace":"/socket.io"
}
]
}
]
},
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3006"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/ptz/*"
]
}
]
},
{
"handle":[
{
"handler":"subroute",
"routes":[
{
"handle":[
{
"handler":"reverse_proxy",
"headers":{
"request":{
"set":{
"Access-Control-Allow-Credentials":[
"true"
],
"Access-Control-Allow-Headers":[
"Cache-Control,Content-Type"
],
"Access-Control-Allow-Origin":[
"*"
],
"X-Forwarded-Proto":[
"{http.request.scheme}"
],
"X-Real-Ip":[
"{http.request.remote.host}"
]
}
}
},
"upstreams":[
{
"dial":"localhost:3001"
}
]
}
]
}
]
}
],
"match":[
{
"path":[
"/api/*"
]
}
]
},
{
"handle":[
{
"handler":"file_server",
"hide":[
"/etc/caddy/Caddyfile"
]
}
]
}
]
}
}
},
"tls":{
"automation":{
"policies":[
{
"issuer":{
"module":"internal"
}
}
]
}
}
}
}
3. The problem I’m having:
I am trying to use json api to load updated config
I am using axios - but I get a 404 error
4. Error messages and/or full log output:
from debug:
Request failed with status code 404
Error: Internal Server Error
from Output:
HTTP/1.1 500 Internal Server Error
Content-Security-Policy: default-src 'none'
X-DNS-Prefetch-Control: off
Expect-CT: max-age=0
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: no-referrer
X-XSS-Protection: 0
Access-Control-Allow-Origin: *
Content-Type: text/html; charset=utf-8
Content-Length: 366
Vary: Accept-Encoding
Date: Tue, 18 Aug 2020 17:34:55 GMT
Connection: keep-alive
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Internal Server Error<br> at /path/to/file.js:91:22<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre>
</body>
</html>
5. What I already tried:
This is the JavaScript code I am calling:
function putConfig (config) {
return new Promise((resolve, reject) => {
axios({
method: 'post',
url: 'http://localhost:2019/load/',
headers: {
'Content-Type': 'application/json'
},
data: { ...config }
})
.then(results => {
console.log(results)
resolve(results.data)
})
.catch(error => {
console.log(error)
reject(error.message)
})
})
}
I’d like to note that getting the config works with this code and returns the above json config:
function getConfig () {
return new Promise((resolve, reject) => {
axios({
method: 'get',
url: 'http://localhost:2019/config/'
})
.then(results => {
// console.log(results)
resolve(results.data)
})
.catch(error => {
reject(error)
})
})
}