Fwd: ZnZincStaticServerAdaptor, redirect on 404
Hi Dave,
I don't know if there's a cleaner way. Seems like it should be fine as you've written it, assuming you never want a 404. I'm forwarding your note to the Pharo users list to see if someone else has any ideas
Good luck
Paul
-------- Original Message -------- Subject: ZnZincStaticServerAdaptor, redirect on 404 Date: Sat, 21 Sep 2013 17:18:43 -0700 From: lasmiste@gmail.com To: pdebruic@gmail.com
Hi Paul, I'm playing with your ZnZincStaticServerAdaptor, it's working very well. I've a question, I start the server this way ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: 'myRepository'. and also my app is the default one WADispatcher default defaultName: 'myApp'. When I point to http://localhost:8080/anExistingStaticFile.jpg everything's fine but when I go to http://localhost:8080/wrongUrl it returns a 404, that is ok, but I'd like I've been redirected to http://localhost:8080/. So I looked at the code and found ZnStaticFileServerDelegate>>handleRequest:
handleRequest: request "Server delegate entry point"
| actualFilename | (#(#GET #HEAD) includes: request method) ifFalse: [ ^ ZnResponse methodNotAllowed: request ]. actualFilename := self actualFilenameFor: request uri. ^ actualFilename notNil ifTrue: [ (self redirectNeededFor: request uri actualFilename: actualFilename) ifTrue: [ self directoryRedirectFor: request uri ] ifFalse: [ self responseForFile: actualFilename fromRequest: request ] ] ifFalse: [ ZnResponse notFound: request uri ]
I changed the last ifFalse: branch with ifFalse: [ZnResponse redirect: '/' ] Now it works, but it's a bit too hackish, is there a cleaner way to to it? TIA Dave
_____________________________________ Sent from http://forum.world.st
participants (1)
-
Paul DeBruicker