UNPKG

servatron

Version:

Create a handler that can server static files using the NodeJS http/http2 modules, or use the inbuilt cli server to quickly run a web server.

25 lines (24 loc) 765 B
import path from 'path'; import { PathType, getPathInfo } from './getPathInfo.js'; /** * Recursively look through a list of directories to find * a path that exists. * * @param {Array<string>} directories An array of directory paths * @param {string} pathname The relative to find **/ export async function searchDirectoriesForPath(directories, pathname) { for (const directory of directories) { const filePath = path.join(directory, pathname); const filePathType = await getPathInfo(filePath); if (filePathType !== PathType.NotFound) { return { directory, filePath, filePathType }; } } return null; } export default searchDirectoriesForPath;