
import express, { Router } from 'express';

interface Options {
    port: number;
    routes: Router;
}


export class Server {
        private app = express();
        private readonly port: number;
        private readonly routes: Router;

    constructor (options : Options) {
        const {port, routes} = options;
        this.port = port;
        this.routes = routes;
        }



    

    async start() {
        /*middleware*/
        // para recebir el body como json
        this.app.use(express.json());
        // para recebir el body como urlencoded
        this.app.use(express.urlencoded({ extended: true }));
       //* Public folder


       // Routes
        this.app.use(this.routes);



        // ponner servido a escuchar en el puerto 8080
        this.app.listen(this.port, () => {
            console.log(`Server is running on port ${this.port}`);
        });
    }

}

