Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
Couple of minor fixes, update readme
Matthew Holt committed
Dec 31, 2019 at 22:51 UTC
3d9f8eac08e172d99eafb396f161263fd444c073
5 files changed
+62
-19
README.md
+11
-11
@@ -112,7 +112,7 @@ $ ./caddy stop
112
113
Note that this will stop any process named the same as `os.Args[0]`.
114
115
-For other commands, please see [the Caddy 2 documentation](https://github.com/caddyserver/caddy/wiki/v2:-Documentation).
115
+For other commands, please see [the Caddy 2 documentation](https://caddyserver.com/docs/command-line).
116
117
### Caddyfile
118
@@ -128,7 +128,7 @@ php_fastcgi /blog unix//path/to/socket
128
file_server
129
```
130
131
-Instead of being its primary mode of configuration, an internal _config adapter_ adapts the Caddyfile to Caddy's native JSON structure. You can see it in action with the [`adapt` command](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#adapt):
131
+Instead of being its primary mode of configuration, an internal _config adapter_ adapts the Caddyfile to Caddy's native JSON structure. You can see it in action with the [`adapt` command](https://caddyserver.com/docs/command-line#caddy-adapt):
132
133
```bash
134
$ ./caddy adapt --config path/to/Caddyfile --adapter caddyfile --pretty
@@ -158,18 +158,18 @@ Caddy 2 exposes an unprecedented level of control compared to any web server in
158
159
Nearly all of Caddy 2's configuration is contained in a single config document, rather than being spread across CLI flags and env variables and a configuration file as with other web servers (and Caddy 1).
160
161
-To wield the power of this design, you need to know how the config document is structured. Please see the [the Caddy 2 documentation in our wiki](https://github.com/caddyserver/caddy/wiki/v2:-Documentation) for details about Caddy's config structure.
161
+To wield the power of this design, you need to know how the config document is structured. Please see the [the Caddy 2 documentation in our wiki](https://caddyserver.com/docs/json/) for details about Caddy's config structure.
162
163
-Configuration is normally given to Caddy through an API endpoint, which is likewise documented in the wiki pages. However, you can also use config files of various formats with [config adapters](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#config-adapters).
163
+Configuration is normally given to Caddy through an API endpoint, which is likewise documented in the wiki pages. However, you can also use config files of various formats with [config adapters](https://caddyserver.com/docs/config-adapters).
164
165
166
## Full Documentation
167
168
-Caddy 2 is very much in development, so the documentation is an ongoing WIP, but the latest will be in our wiki for now:
168
+Caddy 2 is very much in development, and so is its documentation. You can find it here:
169
170
-**https://github.com/caddyserver/caddy/wiki/v2:-Documentation**
170
+**https://caddyserver.com/docs/**
171
172
-Note that breaking changes are expected until the stable 2.0 release.
172
+Note that breaking changes are expected until the stable 2.0 release. The v2 Caddyfile will probably be the last thing documented, as it is rapidly changing.
173
174
175
## List of Improvements
@@ -238,11 +238,11 @@ And a few major features still being worked on:
238
239
### How do I configure Caddy 2?
240
241
-Caddy's primary mode of configuration is a REST API, which accepts a JSON document. The JSON structure is described [in the wiki](https://github.com/caddyserver/caddy/wiki/v2:-Documentation). The advantages of exposing this low-level structure are 1) it has near-parity with actual memory initialization, 2) it allows us to offer wrappers over this configuration to any degree of convenience that is needed, and 3) it performs very well under rapid config changes.
241
+Caddy's primary mode of configuration is a REST API, which accepts a JSON document. The JSON structure is described [interactively in the docs](https://caddyserver.com/docs/json/). The advantages of exposing this low-level structure are 1) it has near-parity with actual memory initialization, 2) it allows us to offer wrappers over this configuration to any degree of convenience that is needed, and 3) it performs very well under rapid config changes.
242
243
-Basically, you will [start Caddy](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#start), then [POST a JSON config to its API endpoint](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#post-load).
243
+Basically, you will [start Caddy](https://caddyserver.com/docs/command-line#caddy-run), then [POST a JSON config to its API endpoint](https://caddyserver.com/docs/api#post-load).
244
245
-Although this makes Caddy 2 highly programmable, not everyone will want to configure Caddy via JSON with an API. Sometimes we just want to give Caddy a simple, static config file and have it do its thing. That's what **[config adapters](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#config-adapters)** are for! You can configure Caddy more ways than one, depending on your needs and preferences. See the next questions that explain this more.
245
+Although this makes Caddy 2 highly programmable, not everyone will want to configure Caddy via JSON with an API. Sometimes we just want to give Caddy a simple, static config file and have it do its thing. That's what **[config adapters](https://caddyserver.com/docs/config-adapters)** are for! You can configure Caddy more ways than one, depending on your needs and preferences. See the next questions that explain this more.
246
247
### Caddy 2 feels harder to use. How is this an improvement over Caddy 1?
248
@@ -254,7 +254,7 @@ Yes! Caddy's native JSON configuration via API is nice when you are automating c
254
255
The v2 Caddyfile is very similar to the v1 Caddyfile, but they are not compatible. Several improvements have been made to request matching and directives in v2, giving you more power with less complexity and fewer inconsistencies.
256
257
-Caddy's default _config adapter_ is the Caddyfile adapter. This takes a Caddyfile as input and [outputs the JSON config](https://github.com/caddyserver/caddy/wiki/v2:-Documentation#adapt). You can even run Caddy directly without having to see or think about the underlying JSON config.
257
+Caddy's default _config adapter_ is the Caddyfile adapter. This takes a Caddyfile as input and [outputs the JSON config](https://caddyserver.com/docs/command-line#caddy-adapt). You can even run Caddy directly without having to see or think about the underlying JSON config.
258
259
The following _config adapters_ are already being built or plan to be built:
260
caddy.go
+16
-6
@@ -23,7 +23,9 @@ import (
23
"io/ioutil"
24
"log"
25
"net/http"
26
+ "os"
27
"path"
28
+ "path/filepath"
29
"runtime/debug"
30
"strconv"
31
"strings"
@@ -262,13 +264,21 @@ func unsyncedDecodeAndRun(cfgJSON []byte) error {
264
newCfg.Admin.Config == nil ||
265
newCfg.Admin.Config.Persist == nil ||
266
*newCfg.Admin.Config.Persist) {
265
- err := ioutil.WriteFile(ConfigAutosavePath, cfgJSON, 0600)
266
- if err == nil {
267
- Log().Info("autosaved config", zap.String("file", ConfigAutosavePath))
268
- } else {
269
- Log().Error("unable to autosave config",
270
- zap.String("file", ConfigAutosavePath),
267
+ dir := filepath.Dir(ConfigAutosavePath)
268
+ err := os.MkdirAll(dir, 0700)
269
+ if err != nil {
270
+ Log().Error("unable to create folder for config autosave",
271
+ zap.String("dir", dir),
272
zap.Error(err))
273
+ } else {
274
+ err := ioutil.WriteFile(ConfigAutosavePath, cfgJSON, 0600)
275
+ if err == nil {
276
+ Log().Info("autosaved config", zap.String("file", ConfigAutosavePath))
277
+ } else {
278
+ Log().Error("unable to autosave config",
279
+ zap.String("file", ConfigAutosavePath),
280
+ zap.Error(err))
281
+ }
282
}
283
}
284
cmd/commandfuncs.go
+1
-1
@@ -498,7 +498,7 @@ func cmdValidateConfig(fl Flags) (int, error) {
498
499
func cmdHelp(fl Flags) (int, error) {
500
const fullDocs = `Full documentation is available at:
501
-https://github.com/caddyserver/caddy/wiki/v2:-Documentation`
501
+https://caddyserver.com/docs/command-line`
502
503
args := fl.Args()
504
if len(args) == 0 {
modules.go
+1
-1
@@ -96,7 +96,7 @@ type ModuleID string
96
func (id ModuleID) Namespace() string {
97
lastDot := strings.LastIndex(string(id), ".")
98
if lastDot < 0 {
99
- return string(id)
99
+ return ""
100
}
101
return string(id)[:lastDot]
102
}
modules_test.go
+33
@@ -83,3 +83,36 @@ func TestGetModules(t *testing.T) {
83
}
84
}
85
}
86
+
87
+func TestModuleID(t *testing.T) {
88
+ for i, tc := range []struct {
89
+ input ModuleID
90
+ expectNamespace string
91
+ expectName string
92
+ }{
93
+ {
94
+ input: "foo",
95
+ expectNamespace: "",
96
+ expectName: "foo",
97
+ },
98
+ {
99
+ input: "foo.bar",
100
+ expectNamespace: "foo",
101
+ expectName: "bar",
102
+ },
103
+ {
104
+ input: "a.b.c",
105
+ expectNamespace: "a.b",
106
+ expectName: "c",
107
+ },
108
+ } {
109
+ actualNamespace := tc.input.Namespace()
110
+ if actualNamespace != tc.expectNamespace {
111
+ t.Errorf("Test %d: Expected namespace '%s' but got '%s'", i, tc.expectNamespace, actualNamespace)
112
+ }
113
+ actualName := tc.input.Name()
114
+ if actualName != tc.expectName {
115
+ t.Errorf("Test %d: Expected name '%s' but got '%s'", i, tc.expectName, actualName)
116
+ }
117
+ }
118
+}