I have an express.js based cloud functions app on firebase in a function named api
. To use a custom domain, I\'m trying to use Firebase Hosting rewrites to rout
Another option, if you want both cloudFunction
and hosted
URLS to work is to check if the URL is coming from the hosted URL.
You'd use this function at any time you wanted the params.
export const splitParams = (req: any): string[] => {
let params = req.params[0];
const vals: string[] = [];
// If params starts with a '/' remove it
params = params.startsWith('/')
? params.substr(1, params.length - 1)
: params;
params = params.split('/');
// For hosted URLs the parameters need to be shifted
if (
req.headers['x-forwarded-host'] === 'myURL'
) {
params.shift();
}
for (const param of params) {
if (param !== '') {
vals.push(param);
}
}
return vals;
};