Map entire subdomain to Azure Function - azure

Is there a way to map an entire subdomain to an Azure Function and pass in the folder structure without proxying it through a VM or App Service? For instance, https://example.com/path/to/name would pass into an Azure Function something like "path/to/name"?

I was able to resolve this with the help of https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies.
After creating a new Function App with an Azure Function using JavaScript with an HTTP Trigger, create a Functions Proxy with a route template of {*path} and a Backend URL of https://localhost/api/<trigger name>?code=<trigger code>&path={path}. On a GET, the path is available at req.query.path, and the original url is available at req.originalUrl.

Related

migrate old azure function API's to new azure function without changing url

earlier we were using azure function app (lets name it func-dev-01 ) for making http function with HTTP trigger which create url as
**https://{function_name_dev}.azurewebsites.net/api/{name}?code=12345678910 ,
**
but for some reason now we are migrating to new azure function app (lets name it fun-prod-01) which create url
** https://{function_name_prod}.azurewebsites.net/api/{name}?code=11121314151617
**
Note: name of both azure function and code are different which is making 2 url's different
How to get same url as old azure function using new azure function ?
You can't. The DNS is provided / handled by AZURE. For such reasons, you should use custom domain and map the way you want:
e.g.
https://mycustomdomain.com (prod)
https://dev.mycustomdomain.com (dev)

How get Azure Function URL directly by code in Azure Function Apps?

In Azure Portal, you can get function URL directly from portal. there is also another way here that you can get Azure Function URL using Azure ARM API. But I want to know, Is there any way to get "Function URL" by code (Node.js, Python, ...) in Azure Function Apps directly?
For Node.js azure function, you can just use this line of code: req.originalUrl.
Detailed steps as below:
1.In Azure portal, create a Http Trigger function, select JavaScript as it's Programming Language.
2.In the index.js file, add this line of code: context.log(req.originalUrl);
3.Sample code like below:
module.exports = function (context, req) {
context.log(req.originalUrl);
//write you other logic below
};
Please refer to the screenshot below for test result:

My Azure function url says 'segments' instead of my function name

I have a function app hosted on azure when I get the url endpoint of the function it says https://my_function_app.azurewebsites.net/api/{*segments} instead of https://my_function_app.azurewebsites.net/api/function_name. How do I fix this?
Looks like you have set route template.
If you create function on portal, click Integrate blade and delete values in Route template.
If you deploy pre-complied function to Azure, you should remove this setting in your code.
For c#, set Route=null in HttpTrigger attribute in your .cs file. For js, remove route parameter in function.json file.

How to redirect HTTP requests to Azure Blob Storage base urls?

We have a Blob Storage baseurl like this:
https://mycompany.blob.core.windows.net/myprod
.. which has several files and folders inside it.
Now, when at some point an app (not in our control) makes a HTTP request to the above URL, which now returns a 404 not found (this is Blob Storage behavior; accessing the files inside the base url is fine).
And this causes things to blow up in our setup!
So, to workaround this, we want to listen through webhooks the HTTP request made to the baseurl above (only the baseurl, not when HTTP requests are made to files inside it) and return a 200 from an Azure Function.
Is this possible and how?
You cannot intercept calls pointing directly to blob storage. That DNS name (yourname.blob.core.windows.net) routes directly to Azure Blob Storage.
If you specifically need to intercept calls, then you need to route them to a dns name of your app (e.g. yourname.azurewebsites.net or yourname.com mapping to yourname.azurewebsites.net, if it's a web app). At this point, you could redirect to whatever you want (including blob storage URI's).
Note: Any blob URI you redirect to either needs to be public-accessible or have a Shared Access Signature (or policy) for your client app to get to it, otherwise a 404 will result.

Azure Functions Proxy - route to storage account

I could create an azure function proxy with success that routes requests to my blob storage. However, it only works if I specify the Backend URL with the full url to the blob file:
ex:
https://account.blob.core.windows.net/site/index.html
where '/site' is my container name and 'index.html' is my blob name.
I had an understanding that I could use the route template as '/site' and if I leave the Backend URL as 'https://account.blob.core.windows.net/site/' what comes after the last '/' would be routed to my storage account. Did I understand wrong?
UPDATE
After reading this other question Azure Function App Proxy to a blob storage account and update the route template / backend url it works, but if my blob name has an extension it does not work (such as .html). Any clues?
Yes we have identified a bug when URL ends with an .extension and will release the fix in the next few days. Thanks much for the feedback.
In the Azure Functions Proxy documentation they specify how to get the request parameters and pass those to your backend service.
Your template can be /site/{*restOfPath}
And your backend would be https://account.blob.core.windows.net/site/{restOfPath}
I was able to get this working only on files that do NOT have a file extension. So I was able to add an index blob and get to it from https://myfunction.azurewebsites.net/index, however, when I tried index.html, the proxy returned a message "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Resources