Hey
I'll have a website which will distribute a specific service to multiple businesses. I have those businesses registered in a database-table.
database-table:
+----+-----------+---------------+-----+
| ID | subdomain | business_name | ... |
+----+-----------+---------------+-----+
| 1 | a | Business A | |
| 2 | b | Business B | |
| 3 | c | Business C | |
+----+-----------+---------------+-----+
Each business will have a own subdomain on my site.
So the structure will be:
www.mysite.com -> My own site explaining the service
a.mysite.com -> Unique page for Business A
b.mysite.com -> Unique page for Business B
c.mysite.com -> Unique page for Business C
...
File structure:
mysite.com #Folder containing my own site
---- www/
-------- index.html
-------- about.html
-------- register_your_business.html
---- template/ #Folder containing the base-templates for the businesses
-------- index.html
-------- service.html
templates/index.html will be something like this:
<!DOCTYPE html>
<html>
...
<body>
<h1> Welcome to %company_name%</h1>
<p>
...
</p>
</body>
</html>
%company_name% will be replaced by the name of the business depending on the visited subdomain. So if someone visits a.mysite.com the site will show Welcome to Business A. If b.mysite.com is visited Welcome to Business B will be displayed.
The name of the company - among other things which are required to fill in the template - will be fetched from the database-table. That database-table will have an unique column containing the name of the sub-domain.
I will register two domains:
Using CNAME's I can register the sub-domains of my clients.
CNAME's:
CNAME a.mysite.com -> template.mysite.com
CNAME b.mysite.com -> template.mysite.com
CNAME c.mysite.com -> template.mysite.com
The URL will still look like a.mysite.com but the request will be sent to template.mysite.com. The back-end on template.mysite.com will fetch the sub-domain part from my URL and because that serves as an unique identifier in my database-table I can fetch all the required data from my database-table to fill my template.
My two questions now are:
- How can I get the sub-domain part from the visited URL in Rust/Actix? This is needed because it serves as row-identifier to get the data of the visited business from the database-table.
- How can I set this up to test on my localhost?
Now I do this: bind("127.0.0.1:8080") and my site is only accessible on 127.0.0.1.
I can register hosts and virtual hosts using Caddy. But .bind("mysite.local") does not work.
I think I could emulate the CNAME's by doing this in Caddy:
{
local_certs
}
mysite.test {
root * /Users/Name/Sites/mysite.com/www
try_files {path} /index.html
file_server browse
}
a.mysite.test {
root * /Users/Name/Sites/mysite.com/template
try_files {path} /index.html
file_server browse
}
b.mysite.test {
root * /Users/Name/Sites/mysite.com/template
try_files {path} /index.html
file_server browse
}
c.mysite.test {
root * /Users/Name/Sites/mysite.com/template
try_files {path} /index.html
file_server browse
}
Now I only need to know on how to bind my Rust/Actix website to a local domain instead of 127.0.0.1.
Thanks!