Re: EuMVC:Dealing with favicon request
- Posted by ghaberek (admin) Apr 07, 2022
- 730 views
euphoric said...
Does downloading the ZIP not get me the latest code?
Yes.
euphoric said...
I get the same error as before after having replaced the old code with the new stuff... apparently.
The problem is this function in my app:
function unknown(object request) sequence url = map:get(request,"PATH_INFO") map response = map:new() addHomePageVars(response) map:put(response, "error", "Unknown path: " & map:get(request,"PATH_INFO")) return redirect( url_for("index", response ) ) end function app:route("*", "unknown")
It's supposed to be a catch-all for unknown paths. I guess I need a different approach...
TBH I haven't really tested the "catch all" approach very much and IMO it'd be safer to maintain specific routes instead of trying to handle "everything."
You should be able to use a static handler for this instead. You can add multiple routes to the same handler.
function static( object request ) sequence path_info = map:get( request, "PATH_INFO" ) sequence local_file = canonical_path( "." & path_info ) if search:begins( current_dir(), local_file ) and file_exists( local_file ) then return send_file( local_file ) end if return response_code( 404 ) end function app:route( "/static/.+", "static" ) -- any file in the "./static" directory app:route( "/favicon\\.ico", "static" ) -- the specific file "favicon.ico"
Note the backslash in second route; because these are regex patterns you have to escape the period.
-Greg