Is it possible to use Pug (nodejs tempalting engine) with firebase cloud functions? I've added and installed the node dependency for Pug. I'm trying to open the template file which is in the a directory views(no such file or directory, open './views/confirm_email.pug'
How do I open a file in my cloud function's index.js (
I had an issue similar to this and I used path.join(__dirname, 'functions/views') and it worked.
I didn't try referencing the path from my cwd, but that might work also... fs.readFileSync('./functions/views/confirm_email.pug')
thank you for your great question.
const functions = require('firebase-functions');
const express = require("express");
const app = express();
app.set("views",__dirname+"/tmp");
app.set("view engine","pug");
app.engine('pug', require('pug').__express);
app.get("/",p3p(p3p.recommended),function(req,res){
res.render("index");
});
app.get("/login",p3p(p3p.recommended),function(req,res){
res.render("login");
});
exports.main = functions.https.onRequest(app);
And then you can access that to link like this .
https://us-central1-[YOURAPP].cloudfunctions.net/main/
https://us-central1-[YOURAPP].cloudfunctions.net/main/login
Looks like this is resolved. There is also a way to map Firebase hosting URLs to a cloud function. See : https://firebase.google.com/docs/hosting/functions
And we have a sample showing how to use Handlebars templating engine with a Cloud function: https://github.com/firebase/functions-samples/tree/master/template-handlebars
Awesome! Cool stuff indeed
Most helpful comment
thank you for your great question.
And then you can access that to link like this .
https://us-central1-[YOURAPP].cloudfunctions.net/main/
https://us-central1-[YOURAPP].cloudfunctions.net/main/login