Azure server can't find handlebars views

Ludovic 0 Reputation points
2024-05-14T12:30:55.9333333+00:00

I am using handlebars to generate html on my server and send it to my users when they land on my express routes. My route looks something like this :


userRouter.get(

    '/template-reset-password/:from',

    async (req: Request, res: Response) => {

        return res.status(200).render('reset-password', { data: req.data });

    },

);

I've setup my express server to accept handleBars files as my view engine. Here's the code I have in my index.ts file :


app.engine(

    'handlebars',

    engine({

        defaultLayout: false,

        layoutsDir: `${__dirname}/public/html`,

    }),

);

app.set('view engine', 'handlebars');

app.set('views', `${__dirname}/public/html`);

On my local machine when i try to access this route, my server send me the html normally and my server can find the directory where my handlebar files are stored. But when I use the same code on my staging server, which is hosted on azure, the server can't find the files and send me this error :


Error: Failed to lookup view "reset-password" in views directory "/usr/src/server/public/html"

    at Function.render (/usr/src/server/node_modules/express/lib/application.js:597:17)

    at ServerResponse.render (/usr/src/server/node_modules/express/lib/response.js:1039:7)

    at /usr/src/server/adapters/primary/routes/user.route.js:114:28

    at Generator.next (<anonymous>)

    at /usr/src/server/adapters/primary/routes/user.route.js:8:71

    at new Promise (<anonymous>)

    at __awaiter (/usr/src/server/adapters/primary/routes/user.route.js:4:12)

    at /usr/src/server/adapters/primary/routes/user.route.js:111:268

    at Layer.handle [as handle_request] (/usr/src/server/node_modules/express/lib/router/layer.js:95:5)

    at next (/usr/src/server/node_modules/express/lib/router/route.js:144:13)

I figured this probably has to do with my azure server config not accepting .handlebar files type, and sending me a "not found" error. Since I'm really new at azure I'd appreciate deep explanations on how to resolve this error. Thanks in advance.

I tried to use handlebars engine on my azure server just like on my local machine. I've encountered the same issue trying to use EJS templates.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,042 questions
{count} votes