add path api to CLI

This commit is contained in:
Gabriel Pastori
2023-11-19 15:01:19 -03:00
parent e5e6e27dbc
commit f28fbfcea0
10 changed files with 207 additions and 62 deletions

View File

@@ -0,0 +1,39 @@
import { Router } from 'express';
import fs from 'fs';
import mime from 'mime-types';
import path from 'path';
import { RouterBroker } from '../abstract/abstract.router';
export class ViewsRouter extends RouterBroker {
constructor() {
super();
const index = fs.readFileSync(path.join(__dirname, '../../../', 'Extras/evolution-manager', 'index.html'));
this.router.get('/*', (req, res) => {
try {
const pathname = req.url.split('?')[0];
// verify if url is a file in dist folder
if (pathname === '/') throw {};
const filePath = path.join(__dirname, '../../../', 'Extras/evolution-manager', pathname);
if (fs.existsSync(filePath)) {
const contentType = mime.lookup(filePath) || 'text/plain';
res.set('Content-Type', contentType);
res.end(fs.readFileSync(filePath));
return;
}
res.set('Content-Type', 'text/html');
res.send(index);
} catch {
res.set('Content-Type', 'text/html');
res.send(index);
}
});
}
public readonly router = Router();
}