import dotenv from "dotenv";
import * as mongoose from "mongoose";


(async () => {
    mongoose.connect ('mongodb://root:super-secret-password@mongo:27017/db?authSource=admin')
        .then (() => {
            console.log ('Mongo DB connected');
        })
        .catch((err: any) => {
            console.log('Mongo DB error connection!');
            console.log(err);
        })
    dotenv.config({path: `.env${process.env.NODE_ENV ? `-${process.env.NODE_ENV}` : ''}`});

    const app = (await import('./app')).app;

    // const hostname = '127.0.0.1';
    const port =  80;
    // change to "server.listen(port, hostname, ()..." to make it work locally and uncomment const hostname
    app.listen(port,() => {
        console.log(`Server running at http://localhost:${port}/`);
    });
})()

