I'm trying to embed an EJS template named 'ui.ejs' into handler.js. The aim is to capture URL query parameters, then pass them to a function name 'ui.js' to capture data, that data is then passed onto the EJS UI template called 'ui.ejs'. But I keep getting this error:
Failure: ENOENT: no such file or directory, open 'D:\Studio\Work\YellowCard\dynamo_serverless_rest\.webpack\service/views/ui.ejs'
Seems webpack is interfering with my directory paths. The directory is under '/views/ui.ejs' NOT '.webpack\service/views/ui.ejs' like the error claims. How do I fix it? Thanks in advance..!
Here's the handler.js code:
// Import modules and dependencies
import {ui} from './index.js';
var ejs = require('ejs');
var fs = require('fs');
// Implementing the UI
export async function UserInterface(event, context, callback) {
// Capture data event parameters
const e = event.queryStringParameters;
// Get UI parameters
let params = await ui(e);
var htmlContent = fs.readFileSync(__dirname + '/views/' + 'ui.ejs', 'utf8');
var template = ejs.compile(htmlContent);
return {
statusCode: 200,
headers: { 'Content-type': 'text/html' },
body: JSON.stringify(template(params)),
};
};