Files
Polaris/server/utils.js
T
Russell2259 f72c4d4638 major update
2023-11-30 21:18:17 -07:00

23 lines
571 B
JavaScript

import path from 'node:path';
import fs from 'node:fs';
/**
* @param {string} url
* @param {string} folderPath
* @returns {{ exists: boolean, path: string }}
*/
const pathToFile = (url = '', folderPath) => {
if (url.endsWith('/')) url = url + 'index.html';
else if (url.split(/[#?]/)[0].split('.').pop().trim() === url) {
if (!fs.existsSync(path.join(folderPath, url))) url = url + '.html';
}
return {
exists: fs.existsSync(path.join(folderPath, url)),
path: path.join(folderPath, url)
};
};
export {
pathToFile
};