Question

Map subdomain to component

I have an App that contains two components, a frontend and a backend. Is it possible map a subdomain to my backend component?

Right now I have a Route path mapped to it but it’s causing issues with Laravel building urls within the app because it doesn’t know it’s running in a “subdirectory”. So all URLS are at the root level.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 13, 2023

Hi there,

As KFSys mentioned already, the DigitalOcean App Platform does not currently support mapping subdomains directly to individual components within the same app.

Given this constraint, a practical workaround is to separate your frontend and backend into two distinct apps on the DigitalOcean App Platform. That way you will have full control over the domain mapping.

Additionally, it would be helpful to understand more about the specific issues you’re facing with URL generation in Laravel. If you could share more details about these problems, there might be further advice or solutions we can offer to address these challenges!

For example, as you mentioned, Laravel needs to be aware that it’s running in a subdirectory for it to generate URLs correctly. You can achieve this by setting the APP_URL in your .env file to include the subdirectory. For instance, if your Laravel backend is accessible at http://yourdomain.com/backend, set APP_URL=http://yourdomain.com/backend.

Alternatively, in your Laravel routes (web.php or api.php), prefix all routes with the subdirectory name. Laravel provides a convenient way to group routes with a prefix, like so:

Route::group(['prefix' => 'backend'], function () {
    // Define your routes here
});

This approach ensures that all your application routes are correctly prefixed with the subdirectory.

Hope that this helps!

Best,

Bobby

KFSys
Site Moderator
Site Moderator badge
December 13, 2023

Heya @jeremib,

I don’t think that is possible at this moment. Having said that, the best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.

https://ideas.digitalocean.com/

Hope that helps!

- KFSys.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel