Remove or mask "_function/" string from HTTP Request Url

Hello!

I’m building an api on Wix Code and need some help with the domain string.

Currently I have the GET HTTP request as:
acme.com/_function/myFunction/

But I want to be able to get the same GET HTTP request like this:
acme.com/myFunction/

Is there a way to do this? I don’t think it possible via 301 redirect within Wix?

Any suggestions? Thanks!

Hi @geekbetting ,
Have you solved this issue?
I am trying to do the same.
Tks.

Why do you need that?

@jonatandor35 hi!
I need to receive GET requests from a third party service that only supports domains as endpoint path. The url request starts with “/weatherstation”, following the domain, my http function’s name, and my endpoint is https://www.klimadata.com/_functions/weatherstation, but I should suppress the “/_functions”. I tried to circumvent this, using no-ip service, redirecting from a host, but it didn’t work. Masking the url didn’t work as well.
Any suggestions?
Thanks!

@contato87032 basically you can create a URL that redirects to the _functions url.
I don’t know if you can do it with wix-router (because of how it works) but if you have an external url that you can use to redirect that should work.

Hi @jonatandor35 ,

Following your suggestion, I have been working in a router. Basically I call a fetch function inside the router function. When I test the router function with Velo “View Funtion Output” functionality, it works properly, calling my endpoint and inserting data in my collection (this 3rd party data service calls as GET request that carries data through a url).

However, when I use curl with GET request, or a web browser, it doesn’t work. Here is the routers.js code, that I adapted from the Wix Velo router template.

import {ok, redirect, notFound, next, forbidden, WixRouterSitemapEntry} from "wix-router";
import {fetch} from 'wix-fetch';

// SAMPLE DATA 
const stationData = { 
 "klima4g": { 
     title: "Klima 4g" 
   }
};

export function weatherstation_Router(request) {

// The request is something like: http://www.klimadata.com/weatherstation/updateweatherstation.php?ID=ABCDEF&PASSWORD=lsrling198&tempf=79.3&...
 
 // Get item name
 const name = "klima4g"

 // Get the item data by name
 const data = stationData[name];

 // Define SEO tags 
 const seoData = { 
      title: data.title, 
      description: "This is a description of " + data.title + " page",
      noIndex: true,
      metaTags: {
 "og:title": data.title
      }
   };

 let url = request.toString();
 let baseUrl = request.baseUrl;
 let prefix = request.prefix;
 
 // The request starts with 24 characters "http://www.klimadata.com" (only http protocol)
 // The content is something like "/weatherstation/updateweatherstation.php?..."
 let content = url.substr(24);    
 
 const apiUrl = "https://www.klimadata.com/_functions"
 const newUrl = apiUrl + content
 console.log(newUrl);
 fetch(newUrl, {"method": "get"})
 
 // Render item page 
 return ok("myRouter-page", data, seoData);
 
}

export function weatherstation_SiteMap(sitemapRequest) {

 // Convert the data to site map entries
 const siteMapEntries = Object.keys(stationData).map((name)=>{
                           const data= stationData[name];
                           const entry = new WixRouterSitemapEntry(name);
                           entry.pageName = "myRouter-page";
                           entry.url = "/myRouter/" + name ;
                           entry.title = data.title;
                           return entry;
 });

 // Return the site map entries
 return siteMapEntries;
}

Any hint?

Thanks!

@contato87032

  1. You forgot “return” before the fetch() and .then() after it.

  2. But anyway I don’t think you can do it like that.

  3. You need to redirect to the _functions/path url.

  4. I think that using router to redirect on Wix won’t work in this case because it’s not pure redirect. Therefore you’re better make the redirection ( 301) from an external site.

P.S.
To test if this redirection really work, I put the _functions url on a URL shortening web service and got a short URL with a structure of domain/path and it worked well. So you should be able to do the same using you own external domain with redirect.

@jonatandor35 I did try using the router to redirect requests to the _functions endpoint, it doesn’t work unfortunately :man_shrugging:

@jonatandor35 and @ahmadnasriya thanks anyway!
I had already tried to redirect with no-ip, but it doesn’t work as well…
I will continue to ask the third party service (Ecowitt) to enhance their functionality to accept different types of endpoints… :sunglasses:
Cheers.

@jonatandor35 and @ahmadnasriya ,
Just to let you know that I accomplished this by using a service provided by https://pipedream.com/
I have created an endpoint there and a workflow to receive the GET call and create another GET call to my endpoint in Wix. :sunglasses:
Thanks again for your time and support!
Cheers.