pugauth0webtask

How to make a pug template render inside of Webtask.io Node/Express serverless app?


I'm trying to render a very simple Pug template from a route in my Webtask.io serverless Node app. Here's my attempt:

'use latest';
import express from 'express';
import pug from 'pug'

const app = express();    
app.set('view engine', 'pug');
...

  app.get('/', (req, res) =>
  {
    var page = `
    #message
        h1 Hello World Foo
        h2 pug's in the house`;

    const HTML = pug.render(page);

    res.status(200).send(HTML)
  });

...
module.exports = fromExpress(app);

and here's the error I'm receiving:

Error: Pug:2:1
    1|
  > 2|     #message
-------^
    3|         h1 Hello World Foo
    4|         h2 pug's in the house

unexpected token "indent"

I've registered Pug as the view engine for the express app, however, it seems like Pug is not getting invoked. What am I missing? How do you register Pug so it will render templates inside a Webtask.io Node app?

I've not been able to find any examples doing this with Pug, however, I've found a post saying it's possible. This post talks about Webtask compiler. I cannot find how you make Pug a compiler.

I'm not married to Pug. Is there a better choice for rendering dynamic HTML from templates that will work with Webtask approach? I've Googled for Handlebars and could not find an example.

Thanks for your time.


Solution

  • Pug works on a two-space indentation standard. That's definitely a pug-formatted error you're seeing so that's hooked up properly.

    Try this template instead:

    #message
      h1 Hello World Foo
      h2 pug's in the house