Skip to content

Commit

Permalink
Remove additional staticDir references, update app.conf & routes in e…
Browse files Browse the repository at this point in the history
…xample apps
  • Loading branch information
jgraham909 committed Feb 21, 2013
1 parent ee46ba2 commit 6597567
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 53 deletions.
24 changes: 0 additions & 24 deletions router.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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, "/") {
Expand Down Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions router_test.go
Expand Up @@ -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"),
Expand All @@ -27,7 +26,6 @@ var routeTestCases = map[string]*Route{
Path: "/app/{id}",
Action: "Application.SaveApp",
pathPattern: regexp.MustCompile("/app/(?P<id>[^/]+)$"),
staticDir: "",
args: []*arg{
{
name: "id",
Expand All @@ -43,7 +41,6 @@ var routeTestCases = map[string]*Route{
Path: "/app/{<[0-9]+>id}",
Action: "Application.SaveApp",
pathPattern: regexp.MustCompile("/app/(?P<id>[0-9]+)$"),
staticDir: "",
args: []*arg{
{
name: "id",
Expand All @@ -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"),
Expand All @@ -70,7 +66,6 @@ var routeTestCases = map[string]*Route{
Path: `/apps/{<\d+>appId}/?`,
Action: "Application.Show",
pathPattern: regexp.MustCompile(`/apps/(?P<appId>\d+)/?$`),
staticDir: "",
args: []*arg{
{
name: "appId",
Expand All @@ -86,7 +81,6 @@ var routeTestCases = map[string]*Route{
Path: "/public/{<.+>filepath}",
Action: "Static.ServeDir",
pathPattern: regexp.MustCompile(`/public/(?P<filepath>.+)$`),
staticDir: "",
args: []*arg{
{
name: "filepath",
Expand All @@ -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<id>[^/]+)/(?P<action>[^/]+)$"),
staticDir: "",
args: []*arg{
{
name: "id",
Expand All @@ -135,7 +117,6 @@ var routeTestCases = map[string]*Route{
Path: "/{controller}/{action}",
Action: "{controller}.{action}",
pathPattern: regexp.MustCompile("/(?P<controller>[^/]+)/(?P<action>[^/]+)$"),
staticDir: "",
args: []*arg{
{
name: "controller",
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions samples/chat/conf/app.conf
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/chat/conf/routes
Expand Up @@ -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")

2 changes: 1 addition & 1 deletion 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]
2 changes: 1 addition & 1 deletion samples/facebook-oauth2/conf/routes
Expand Up @@ -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}
3 changes: 2 additions & 1 deletion samples/i18n/conf/app.conf
Expand Up @@ -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
Expand All @@ -27,7 +28,7 @@ results.pretty=false
results.staging=false
watch=false

module.testrunner =
module.testrunner =

log.trace.output = off
log.info.output = off
Expand Down
2 changes: 1 addition & 1 deletion samples/i18n/conf/routes
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion samples/twitter-oauth/conf/app.conf
@@ -1,4 +1,4 @@
app.secret=e227tafmfs0xrexah43hm34kkrcetav48nwk9x037wp87jkrp06m7n8wc8m7gbag

module.static=github.com/robfig/revel/modules/static
[dev]
[prod]
2 changes: 1 addition & 1 deletion samples/twitter-oauth/conf/routes
Expand Up @@ -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}
1 change: 1 addition & 0 deletions 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]
2 changes: 1 addition & 1 deletion samples/validation/conf/routes
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion skeleton/conf/routes
Expand Up @@ -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}
1 change: 1 addition & 0 deletions testdata/i18n/config/test_app.conf
Expand Up @@ -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
Expand Down

0 comments on commit 6597567

Please sign in to comment.