add manager

This commit is contained in:
Gabriel Pastori
2023-12-11 15:06:42 -03:00
parent d14505d59a
commit b2e144f35c
4 changed files with 22 additions and 28 deletions

View File

@@ -1,14 +1,32 @@
import { Router } from 'express';
import fs from 'fs';
import mime from 'mime-types';
import { RouterBroker } from '../abstract/abstract.router';
import { viewsController } from '../whatsapp.module';
export class ViewsRouter extends RouterBroker {
constructor() {
super();
this.router.get('/', (req, res) => {
return viewsController.manager(req, res);
const basePath = 'evolution-manager/dist';
const indexPath = require.resolve(`${basePath}/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 = require.resolve(`${basePath}${pathname}`);
const contentType = mime.lookup(filePath) || 'text/plain';
res.set('Content-Type', contentType);
res.end(fs.readFileSync(filePath));
} catch {
res.set('Content-Type', 'text/html');
res.send(fs.readFileSync(indexPath));
}
});
}