Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(filePath, 'utf8', function(err, data) {
if (err) {
return console.log('Error loading file to buffer.', err);
}
if (filePath && filePath.includes('index.html')) {
data = renderAltair();
}
// Load the data from the file into a buffer and pass it to the callback
// Using the mime package to get the mime type for the file, based on the file name
callback({ mimeType: mime.lookup(filePath), data: Buffer.from(data) });
});
});
app.get('/', (req, res) => {
if (req.originalUrl.substr(-1) !== '/') {
// We need the trailing slash to enable relative file paths to work
return res.redirect(301, req.originalUrl + '/');
}
return res.send(renderAltair(opts));
});
app.get('/initial_options.js', (req, res) => {
router.get(url, async (ctx, next) => {
ctx.body = renderAltair({ baseURL: ctx.url.replace(/\/?$/, '/'), ...opts });
await next();
})