Expanded index file support to other middlewares (fixes #27)

This commit is contained in:
Matthew Holt 2015-05-05 15:50:42 -06:00
parent a9064a7871
commit 47717fee88
7 changed files with 117 additions and 52 deletions

View file

@ -2,6 +2,7 @@ package setup
import (
"errors"
"net/http"
"path/filepath"
"github.com/mholt/caddy/middleware"
@ -10,7 +11,7 @@ import (
// FastCGI configures a new FastCGI middleware instance.
func FastCGI(c *Controller) (middleware.Middleware, error) {
root, err := filepath.Abs(c.Root)
absRoot, err := filepath.Abs(c.Root)
if err != nil {
return nil, err
}
@ -24,7 +25,9 @@ func FastCGI(c *Controller) (middleware.Middleware, error) {
return fastcgi.Handler{
Next: next,
Rules: rules,
Root: root,
Root: c.Root,
AbsRoot: absRoot,
FileSys: http.Dir(c.Root),
SoftwareName: c.AppName,
SoftwareVersion: c.AppVersion,
ServerName: c.Host,
@ -72,10 +75,11 @@ func fastcgiParse(c *Controller) ([]fastcgi.Rule, error) {
}
rule.SplitPath = c.Val()
case "index":
if !c.NextArg() {
args := c.RemainingArgs()
if len(args) == 0 {
return rules, c.ArgErr()
}
rule.IndexFile = c.Val()
rule.IndexFiles = args
case "env":
envArgs := c.RemainingArgs()
if len(envArgs) < 2 {
@ -98,7 +102,7 @@ func fastcgiPreset(name string, rule *fastcgi.Rule) error {
case "php":
rule.Ext = ".php"
rule.SplitPath = ".php"
rule.IndexFile = "index.php"
rule.IndexFiles = []string{"index.php"}
default:
return errors.New(name + " is not a valid preset name")
}

View file

@ -1,6 +1,8 @@
package setup
import (
"net/http"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/markdown"
"github.com/russross/blackfriday"
@ -14,8 +16,10 @@ func Markdown(c *Controller) (middleware.Middleware, error) {
}
md := markdown.Markdown{
Root: c.Root,
Configs: mdconfigs,
Root: c.Root,
FileSys: http.Dir(c.Root),
Configs: mdconfigs,
IndexFiles: []string{"index.md"},
}
return func(next middleware.Handler) middleware.Handler {

View file

@ -1,6 +1,8 @@
package setup
import (
"net/http"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/templates"
)
@ -13,8 +15,9 @@ func Templates(c *Controller) (middleware.Middleware, error) {
}
tmpls := templates.Templates{
Root: c.Root,
Rules: rules,
Rules: rules,
Root: c.Root,
FileSys: http.Dir(c.Root),
}
return func(next middleware.Handler) middleware.Handler {
@ -43,6 +46,10 @@ func templatesParse(c *Controller) ([]templates.Rule, error) {
rule.Extensions = defaultExtensions
}
for _, ext := range rule.Extensions {
rule.IndexFiles = append(rule.IndexFiles, "index"+ext)
}
rules = append(rules, rule)
}
@ -51,4 +58,4 @@ func templatesParse(c *Controller) ([]templates.Rule, error) {
const defaultPath = "/"
var defaultExtensions = []string{".html", ".htm", ".txt"}
var defaultExtensions = []string{".html", ".htm", ".tmpl", ".tpl", ".txt"}