const express = require('express');
const cors = require('cors');
const app = express();
const path = require("path");
const bodyParser = require('body-parser');
const http = require('http');

const model = require('./models/migration.js');
const apiRoute = require('./app/core/routes/api.route.js');

const corsOptions = {
    origin: '*',
    credentials: true,
};
const client = require('prom-client');
const register = new client.Registry();
const passport = require('passport')
require('./app/core/services/authGoogle.service.js')



client.collectDefaultMetrics({ register });

const httpRequestDurationMicroseconds = new client.Histogram({
    name: 'api_http_request_duration_seconds',
    help: 'Duration of HTTP requests in seconds',
    // labelNames: ["method", "route", "code"],
    // buckets: [0.1, , 0.5, 1, 5, , 10],
});


const customCounter = new client.Counter({
    name: 'my_custom_counter',
    help: 'Custom counter for my application',
});




app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use(
    bodyParser.urlencoded({
        extended: true,
    })
);
app.use(passport.initialize());

const authGoogle = require('./app/core/routes/authGoogle.route.js')
app.use('/auth', authGoogle);

app.use('/api', apiRoute);


app.use("/api/uploads", express.static(path.join(__dirname, "public", "uploads")));


app.use(express.static('public'));

const port = process.env.APP_PORT || 4042;
const server = http.createServer(app);

server.listen(port, () => {
    // model.sequelize.sync({ alter: true });
    console.log(`Server is running on port http://localhost:${port}.`);
});