App’s viewport can be placed in several possible contexts, based on the type of the application:

URL Form

App’s primary viewport:

https://appcloud.mergado.com/apps/myapp/[eshop/<eshopId>[/project/<projectId>]]

App’s widget viewport:

https://appcloud.mergado.com/apps/myapp/widget/[eshop/<eshopId>[/project/<projectId>]]

Examples

App for eshops

MyEshopsApp is of type eshop, all these URLs are valid:

https://appcloud.mergado.com/apps/myeshopsapp/eshop/123/project/456
https://appcloud.mergado.com/apps/myeshopsapp/eshop/123
https://appcloud.mergado.com/apps/myeshopsapp/widget/eshop/123/project/456
https://appcloud.mergado.com/apps/myeshopsapp/widget/eshop/123

App for projects

MyProjectsApp is of type project, these URLs are valid:

https://appcloud.mergado.com/apps/myprojectsapp/eshop/123/project/456
https://appcloud.mergado.com/apps/myprojectsapp/widget/eshop/123/project/456

Behaviour of project app without having project ID specified in its URL is undefined.

https://appcloud.mergado.com/apps/myprojectsapp/eshop/123
https://appcloud.mergado.com/apps/myprojectsapp/widget/eshop/123

App for users

MyUsersApp is of type user, all these URLs are valid:

https://appcloud.mergado.com/apps/myusersapp/eshop/123/project/456
https://appcloud.mergado.com/apps/myusersapp/eshop/123
https://appcloud.mergado.com/apps/myusersapp/
https://appcloud.mergado.com/apps/myusersapp/widget/eshop/123/project/456
https://appcloud.mergado.com/apps/myusersapp/widget/eshop/123
https://appcloud.mergado.com/apps/myusersapp/widget/

We know PHP is not suited to handle this style of routing - not without an additional code, some framework or an external library parsing these pretty-URLs. Because we don’t want to force developers to have to use third-party libraries by default, an additional option is planned to have the routing in a form of GET parameters, which will better suit the way of how pure PHP works.

Front controller & .htaccess

Because the only currently supported routing system follows the pretty-URL style, you’ll most definitely want to use a front controller pattern with .htaccess in the app’s public root handling the collection of requests.

Below is the configuration you can use in your app’s /www/.htaccess file to handle pointing all requests to the a single /www/index.php directory:

RewriteEngine On

# Build Mergado App Cloud rewrite base URL.
SetEnvIfNoCase Request_URI (/apps/.+?/) MERGADO_APPCLOUD_REWRITE_BASE=$1

# Redirect trailing slashes if not a directory.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ %{env:MERGADO_APPCLOUD_REWRITE_BASE}$1 [L,R=301]

# Handle front controller.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{env:MERGADO_APPCLOUD_REWRITE_BASE}index.php [L]