From 659756781c4a73e4fcfb8ecfc712a6fc6e24e519 Mon Sep 17 00:00:00 2001 From: Jeff Graham Date: Thu, 21 Feb 2013 02:13:54 -0800 Subject: [PATCH] Remove additional staticDir references, update app.conf & routes in example apps --- router.go | 24 ------------------------ router_test.go | 20 -------------------- samples/chat/conf/app.conf | 2 ++ samples/chat/conf/routes | 2 +- samples/facebook-oauth2/conf/app.conf | 2 +- samples/facebook-oauth2/conf/routes | 2 +- samples/i18n/conf/app.conf | 3 ++- samples/i18n/conf/routes | 2 +- samples/twitter-oauth/conf/app.conf | 2 +- samples/twitter-oauth/conf/routes | 2 +- samples/validation/conf/app.conf | 1 + samples/validation/conf/routes | 2 +- skeleton/conf/routes | 2 +- testdata/i18n/config/test_app.conf | 1 + 14 files changed, 14 insertions(+), 53 deletions(-) diff --git a/router.go b/router.go index 2b0e5f7e3..d6302d8a2 100644 --- a/router.go +++ b/router.go @@ -18,7 +18,6 @@ type Route struct { FixedParams []string // e.g. "arg1","arg2","arg3" (CSV formatting) pathPattern *regexp.Regexp // for matching the url path - staticDir string // e.g. "public" from action "staticDir:public" args []*arg // e.g. {id} from path /app/{id} actionPattern *regexp.Regexp } @@ -59,24 +58,6 @@ func NewRoute(method, path, action, fixedArgs string) (r *Route) { FixedParams: fargs, } - // Handle static routes - if strings.HasPrefix(r.Action, "staticDir:") { - if r.Method != "*" && r.Method != "GET" { - WARN.Print("Static route only supports GET") - return - } - - if !strings.HasSuffix(r.Path, "/") { - WARN.Printf("The path for staticDir must end with / (%s)", r.Path) - r.Path = r.Path + "/" - } - - r.pathPattern = regexp.MustCompile("^" + r.Path + "(.*)$") - r.staticDir = r.Action[len("staticDir:"):] - // TODO: staticFile: - return - } - // URL pattern // TODO: Support non-absolute paths if !strings.HasPrefix(r.Path, "/") { @@ -238,11 +219,6 @@ func (router *Router) parse(content string, validate bool) *Error { // Check that every specified action exists. func (router *Router) validate(route *Route) *Error { - // Skip static routes - if route.staticDir != "" { - return nil - } - // Skip variable routes. if strings.ContainsAny(route.Action, "{}") { return nil diff --git a/router_test.go b/router_test.go index 58311a97b..b36a264d4 100644 --- a/router_test.go +++ b/router_test.go @@ -16,7 +16,6 @@ var routeTestCases = map[string]*Route{ Path: "/", Action: "Application.Index", pathPattern: regexp.MustCompile("/$"), - staticDir: "", args: []*arg{}, FixedParams: []string{}, actionPattern: regexp.MustCompile("Application\\.Index"), @@ -27,7 +26,6 @@ var routeTestCases = map[string]*Route{ Path: "/app/{id}", Action: "Application.SaveApp", pathPattern: regexp.MustCompile("/app/(?P[^/]+)$"), - staticDir: "", args: []*arg{ { name: "id", @@ -43,7 +41,6 @@ var routeTestCases = map[string]*Route{ Path: "/app/{<[0-9]+>id}", Action: "Application.SaveApp", pathPattern: regexp.MustCompile("/app/(?P[0-9]+)$"), - staticDir: "", args: []*arg{ { name: "id", @@ -59,7 +56,6 @@ var routeTestCases = map[string]*Route{ Path: "/app/?", Action: "Application.List", pathPattern: regexp.MustCompile("/app/?$"), - staticDir: "", args: []*arg{}, FixedParams: []string{}, actionPattern: regexp.MustCompile("Application\\.List"), @@ -70,7 +66,6 @@ var routeTestCases = map[string]*Route{ Path: `/apps/{<\d+>appId}/?`, Action: "Application.Show", pathPattern: regexp.MustCompile(`/apps/(?P\d+)/?$`), - staticDir: "", args: []*arg{ { name: "appId", @@ -86,7 +81,6 @@ var routeTestCases = map[string]*Route{ Path: "/public/{<.+>filepath}", Action: "Static.ServeDir", pathPattern: regexp.MustCompile(`/public/(?P.+)$`), - staticDir: "", args: []*arg{ { name: "filepath", @@ -99,23 +93,11 @@ var routeTestCases = map[string]*Route{ actionPattern: regexp.MustCompile("Static\\.ServeDir"), }, - "GET /public/ staticDir:www": &Route{ - Method: "GET", - Path: "/public/", - Action: "staticDir:www", - pathPattern: regexp.MustCompile("^/public/(.*)$"), - staticDir: "www", - args: []*arg{}, - FixedParams: []string{}, - actionPattern: nil, - }, - "* /apps/{id}/{action} Application.{action}": &Route{ Method: "*", Path: "/apps/{id}/{action}", Action: "Application.{action}", pathPattern: regexp.MustCompile("/apps/(?P[^/]+)/(?P[^/]+)$"), - staticDir: "", args: []*arg{ { name: "id", @@ -135,7 +117,6 @@ var routeTestCases = map[string]*Route{ Path: "/{controller}/{action}", Action: "{controller}.{action}", pathPattern: regexp.MustCompile("/(?P[^/]+)/(?P[^/]+)$"), - staticDir: "", args: []*arg{ { name: "controller", @@ -164,7 +145,6 @@ func TestComputeRoute(t *testing.T) { eq(t, "Path", actual.Path, expected.Path) eq(t, "Action", actual.Action, expected.Action) eq(t, "pathPattern", fmt.Sprint(actual.pathPattern), fmt.Sprint(expected.pathPattern)) - eq(t, "staticDir", actual.staticDir, expected.staticDir) eq(t, "len(args)", len(actual.args), len(expected.args)) for i, arg := range actual.args { if len(expected.args) <= i { diff --git a/samples/chat/conf/app.conf b/samples/chat/conf/app.conf index e8960a97c..a02216699 100644 --- a/samples/chat/conf/app.conf +++ b/samples/chat/conf/app.conf @@ -3,6 +3,8 @@ app.secret=pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj http.addr= http.port=9000 +module.static=github.com/robfig/revel/modules/static + [dev] results.pretty=true watch=true diff --git a/samples/chat/conf/routes b/samples/chat/conf/routes index fa413d753..503e09c11 100644 --- a/samples/chat/conf/routes +++ b/samples/chat/conf/routes @@ -23,5 +23,5 @@ GET /websocket/room WebSocket.Room WS /websocket/room/socket WebSocket.RoomSocket # Map static resources from the /app/public folder to the /public path -GET /public/ staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") diff --git a/samples/facebook-oauth2/conf/app.conf b/samples/facebook-oauth2/conf/app.conf index 20c5e9c65..603c00ba1 100644 --- a/samples/facebook-oauth2/conf/app.conf +++ b/samples/facebook-oauth2/conf/app.conf @@ -1,5 +1,5 @@ app.name=Facebook OAuth2 app.secret=ly2bgKNgQ7BSoWW8BZ33Tos9Z9hy2Ck6bFXotLxwSaXk60iXPqlZUKnJpGVoIHhs - +module.static=github.com/robfig/revel/modules/static [dev] [prod] diff --git a/samples/facebook-oauth2/conf/routes b/samples/facebook-oauth2/conf/routes index 209f78d3a..2ee4bc47e 100644 --- a/samples/facebook-oauth2/conf/routes +++ b/samples/facebook-oauth2/conf/routes @@ -6,7 +6,7 @@ GET / Application.Index # Map static resources from the /app/public folder to the /public path -GET /public/ staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") # Catch all * /{controller}/{action} {controller}.{action} diff --git a/samples/i18n/conf/app.conf b/samples/i18n/conf/app.conf index 20bb5fb3f..2f45c8368 100644 --- a/samples/i18n/conf/app.conf +++ b/samples/i18n/conf/app.conf @@ -16,6 +16,7 @@ results.staging=true watch=true #module.testrunner = github.com/robfig/revel/modules/testrunner +module.static=github.com/robfig/revel/modules/static log.trace.output = stdout log.info.output = stderr @@ -27,7 +28,7 @@ results.pretty=false results.staging=false watch=false -module.testrunner = +module.testrunner = log.trace.output = off log.info.output = off diff --git a/samples/i18n/conf/routes b/samples/i18n/conf/routes index 2ce276a32..995b97b45 100644 --- a/samples/i18n/conf/routes +++ b/samples/i18n/conf/routes @@ -8,7 +8,7 @@ GET / Application.Index GET /favicon.ico 404 # Map static resources from the /app/public folder to the /public path -GET /public/ staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") # Catch all * /{controller}/{action} {controller}.{action} diff --git a/samples/twitter-oauth/conf/app.conf b/samples/twitter-oauth/conf/app.conf index c152696f0..fb21e8bba 100644 --- a/samples/twitter-oauth/conf/app.conf +++ b/samples/twitter-oauth/conf/app.conf @@ -1,4 +1,4 @@ app.secret=e227tafmfs0xrexah43hm34kkrcetav48nwk9x037wp87jkrp06m7n8wc8m7gbag - +module.static=github.com/robfig/revel/modules/static [dev] [prod] diff --git a/samples/twitter-oauth/conf/routes b/samples/twitter-oauth/conf/routes index 649ec0f8b..970962114 100644 --- a/samples/twitter-oauth/conf/routes +++ b/samples/twitter-oauth/conf/routes @@ -9,7 +9,7 @@ GET /auth Application.authenticate POST /ws/status Application.setStatus # Map static resources from the /app/public folder to the /public path -GET /public/ staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") # Catch all * /{controller}/{action} {controller}.{action} diff --git a/samples/validation/conf/app.conf b/samples/validation/conf/app.conf index fb04bfe28..60a78c409 100644 --- a/samples/validation/conf/app.conf +++ b/samples/validation/conf/app.conf @@ -1,4 +1,5 @@ app.name=Sample validation app.secret=774a66ffb3d8113a2f730bbb33192251dc521ab0bee1bb0d88290299fe05c618 +module.static=github.com/robfig/revel/modules/static [dev] [prod] diff --git a/samples/validation/conf/routes b/samples/validation/conf/routes index 46176b7d7..9e772d189 100644 --- a/samples/validation/conf/routes +++ b/samples/validation/conf/routes @@ -6,7 +6,7 @@ GET / Application.Index # Map static resources from the app/public folder to /public -GET /public staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") # Catch all * /{controller}/{action} {controller}.{action} diff --git a/skeleton/conf/routes b/skeleton/conf/routes index 2ce276a32..04a16f786 100644 --- a/skeleton/conf/routes +++ b/skeleton/conf/routes @@ -8,7 +8,7 @@ GET / Application.Index GET /favicon.ico 404 # Map static resources from the /app/public folder to the /public path -GET /public/ staticDir:public +GET /public/{<.+>filepath} Static.ServeDir("public") # Catch all * /{controller}/{action} {controller}.{action} diff --git a/testdata/i18n/config/test_app.conf b/testdata/i18n/config/test_app.conf index a61ea36cd..9169b2d69 100644 --- a/testdata/i18n/config/test_app.conf +++ b/testdata/i18n/config/test_app.conf @@ -13,6 +13,7 @@ results.staging=true watch=true module.testrunner = github.com/robfig/revel/modules/testrunner +module.static=github.com/robfig/revel/modules/static log.trace.output = off log.info.output = stderr