import {C4CApiHandler, C4CApiRequest} from "../index"; import {Response} from '../response'; const path = require('path'); const fs = require('fs'); const handler = (staticBasePath: string): C4CApiHandler => { return ((req: C4CApiRequest, res: Response, next: () => void) => { if (req.httpMethod === 'GET' || req.httpMethod === 'HEAD') { const filePath = path.join(staticBasePath, req.path); if (fs.existsSync(filePath)) { const fileState = fs.statSync(filePath); if (fileState.isFile()) { res.file(filePath); } else { next(); } } else { next(); } } else { next(); } }) as C4CApiHandler; }; export default handler;