mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-12-19 11:32:18 -06:00
add path api to CLI
This commit is contained in:
39
lib/api/view.router.ts.patch
Normal file
39
lib/api/view.router.ts.patch
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user