How to set a subfolder as webapp root on Azure Linux

444 Views Asked by At

I'm using Linux on Azure to host my webapp and it deploys fine. My local dev tree structure looks like this:

  • build
  • node_modules
  • src .deployment .env .gitignore package.json README.json ...

When I deploy to Azure it looks like this:

  • dist
  • node_modules

Within one of my files I re-utilize some components from a node module like so:

import Password from '../../../node_modules/path/to/components/forms/field-types/Password';

There are 2 potential ways to make this work:

  1. Deploy /dist into the root and have node_modules as a sibling but this then makes the relative path above break and ES6 doesn't allow dynamic import strings nor for them to be within blocks
  2. Set the /dist folder as the application root which is actually correct (eg: it contains server.js) and then the relative paths would be correct

I'd prefer #2 however the capability for doing virtual path mapping in Azure doesn't seem to exist so it seems I'd need to leverage .htaccess. I'm curious if there are any other ways to do this and also if the root is set to /dist will the relative path still work or will it be blocked by the server?

Thanks.

1

There are 1 best solutions below

0
On

.htaccess file setting **RewriteEngine On** on the request path. So if you add an admin-specific .htaccess file in the "subfolder" subfolder, this will preempt the www one and circumvent this problem.

EX:

RedirectMatch ^/my_folder/(.+)/card.jpg$ /script_folder/image.php?perameter=$1

This willredirect /my_folder/xyz/card.jpg to /script_folder/image.php?perameter=xyz changing the address bar from typed url to a new url. If you want the browser to stay on the typed url, you can use the following mod rewrite based solution :

RewriteEngine on

RewriteRule ^my_folder/(.+)/card.jpg$ /script_folder/image.php?perameter=$1 [L]

Please refer this DOC:

Deploy files to App Service - Azure App Service | Microsoft Learn