const fs = require('fs');
const path = require('path');

const express = require('express');
const compression = require('compression');
const bodyParser = require('body-parser');

// frontend
const frontend = async (app) => {
    app.set('protocol', process.env.PROTOCOL);
    app.set('host', process.env.HOST);
    app.set('port', process.env.PORT_FRONTEND);

    app.use(compression());
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));

    const frontendFolder = path.join(process.cwd(), '../PosFrontend/POSFrontend');

    // frontend files
    app.use('/', express.static(frontendFolder));

    // frontend endpoint
    app.use('/*', (req, res, next) => { res.sendFile('index.html', {root: frontendFolder}); });
};

module.exports = frontend;
