-
Notifications
You must be signed in to change notification settings - Fork 12
Logical architecture
Basically the code is splitted in the following way:
A website is composed of a main application (stored directly in the src folder and "launched" by main.cpp), this main application will receive all the HTTP request. In the constructor we will attach to it some "sub-application" (named controllers). The main application is not used directly to display pages, it will always delegate this to a controllers.
The goal of the main application is to do all the "before" routing actions: like for example checking that the URL is correctly formatted (for example if a website is multilingual and you have the following url schema:
http://language.domain.tld/controller/action/parameters1/parameters2
you may want to allow users to do
http://domain.tld/controller/action/parameters1/parameters2
and to have code that redirect to the version of the website in the same language as the user's one.
Or if you change the overall url schema during the lifetime of your application, it's the main application that will be used to do the rewriting.
An other example: if your application is only to be accessed by some IPs (and if your webserver does not permit you to do so directly in the webserver configuration), you can do the check here.
Once this post-routing code done, the application will transfer part of URL, the cookies, sessions etc. to a controller (see the section below to more in-depth description of what is a controller). As an application has several controllers attached, the url will be used to determine which one to call.
for example considering this application with 3 controllers
- Tatowiki //main application//
- Articles //controller//
- Module1 //controller//
- Pages //controller//
and the following code use to attach them:
add(articles,"^/articles(.*)",1);
add(module1,"^/module1(.*)",1);
//%%%NEXT_CONTROLLER_DISPATCHER_MARKER%%%, do not delete
add(pages, "/(.*)", 1);then the following url
http://en.example.com/articles/show/1
will call the controller Articles and will send it the url '/show/1'