I'm using firebase serverless function to store my lead,
I'm under impression that firebase use request object from express.js, so here's my code:
export const addLead = functions
.https.onRequest(async (req, res) => {
const data = {
name: req.body.name,
phoneNumber: req.body.phoneNumber,
email: req.body.email,
path: req.body.path,
};
console.log(
JSON.stringify({
headers: req.headers,
method: req.method,
url: req.url,
httpVersion: req.httpVersion,
body: req.body,
cookies: req.cookies,
path: req.path,
protocol: req.protocol,
query: req.query,
hostname: req.hostname,
ip: req.ip,
originalUrl: req.originalUrl,
params: req.params,
})
);
const docRef = await db.collection("leads").add(data);
// ... omitted
});
Here's the result of the console log in jsonviewer:
How to get the req.originalUrl, for ex: /services/renovation?q=houserenovation.
Or
How do I get the fullURL of the request is coming from? for ex: http://localhost:3000/services/renovation?q=houserenovation
It has to be http function because I don't want to install javascript on the client, it's submitted through form.
I already tried in staging server, it's still showing empty "/"