1

I used to develop in English, but this time, the webApp i'm building is only for people in my city, which is in France.

In nitrogen, when you call "/user/login", nitrogen calls user_login:main(). I would like nitrogen to call user_login:main() when the request is "/utilisateur/connexion".

I would like nitrogen to call ads_people:main() when the request is "/annonces/personnes", etc.

Is there a way to achieve that properly ?

Many thanks !

2 Answers 2

2

You can do this easily by using Nitrogen's named_route_handler plugin. Steps are:

  1. Insert following line before call to nitrogen:run():

    wf_handler:set_handler(named_route_handler, get_routes()).
    
  2. Add get_routes/0 function:

    get_routes() -> [
        {"/utilisateur/connexion", user_login},
        {"/annonces/personnes", annonces_persons},
        etc...
    ].
    

    First element in a tuple is the path in URL and the second is the name of the corresponding module which will handle requests with such path.

0

Use a proxy in front of Nitrogen like nginx to do that kind of URL rewriting.

Altrernatively, check out some of the documentation in src/handlers/route/named_route_handler.erl if you wanted to do it in pure nitrogen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.