Hello, I am trying to make a custom router. For th...
# lucee
e
Hello, I am trying to make a custom router. For this I am trying to grab the user requested URL from the
application.cfc
. The problem is when a invalid directory or URL is received
lucee
directly throwing
404 page
. I just want to get the requested URL and bypass this
404 error
. Can anyone here help me with by telling me how should I proceed?
d
I would maybe take a look at how other routers do things, as there's a few examples of them with the various frameworks out there, and a few ways to work it, from using the request cycle, to doing something "onError"
I bet Ben has a blog post on exactly how to do it, but in the meantime, you can look at the lifecycle stuff here. Most implementations probably use
onRequestStart
? https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applicati[…]-the-application-and-its-event-handlers-in-application-c.html
e
I have tried to look how
ColdBox
have solved the problem but did not actually got it as I am very new to CF. Also, I have found
onMissingTemplate()
that will only let you know if any
*.cfm
file is not found but no luck with the URL.
I understand
onRequestStart()
receives only the valid URLs and can be fetched using
CGI
but the invalid URLs or the non-existent directory is directly giving error and not reaching
onRequestStart()
method.
d
I believe that
onRequestStart
is called regardless of if the template exists or not
that looks to be what yer after
e
Thank you but this doesn't solve the issue as my problem is with
URL
and not with the template
*.cfm
. For example, if I have a URL like
localhost:8888/hello
note that this directory doesn't exist and if I run the server and try to visit the URL, the
onRequest()
will not dump anything and will somehow redirected to the
404 page
. No way I am able to grab the URL because of that.
d
Ah, that's going to be up to how you have your web server configured, you probably do want rewrites, so maybe look into commandbox and how it does rewrites?
otherwise just ensure that every request is passed to the cf engine, versus just the ones that match the cf pattern
e
Yes I have already tried to
URL Rewrite
taking help from here https://stackoverflow.com/questions/61541516/how-to-implement-urlrewrite-in-lucee . But no luck so far and I am not sure how to redirect all the request to
Application.cfc
. Do you have any idea?
👍 1