{"size": 1354, "ext": "js", "max_stars_repo_path": "app/src/app.js", "max_stars_repo_name": "AdamGPrice/Table-Booking-Application", "max_stars_repo_stars_event_min_datetime": "2021-01-28T22:21:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-28T22:21:55.000Z", "max_issues_repo_path": "app/src/app.js", "max_issues_repo_name": "AdamGPrice/Table-Booking-Application", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/src/app.js", "max_forks_repo_name": "AdamGPrice/Table-Booking-Application", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.08, "max_line_length": 77, "alphanum_fraction": 0.6410635155}
const express = require('express');
const morgan = require('morgan');
const compression = require('compression');
const helmet = require('helmet');
const path = require('path');

require('dotenv').config();

const app = express();
const services = require('./services/index')


// npm middlewares
app.use(morgan('tiny'));
app.use(compression());
app.use(helmet());
app.use(express.json());

// All api requests will be routed to services
app.use('/api', services);

// Config the static files
app.use(express.static('public'));
app.use('/css', express.static(path.join(__dirname, '../public/css')));
app.use('/js', express.static(path.join(__dirname, '../public/js')));
app.use('/vendor', express.static(path.join(__dirname, '../public/vendor')));

// Templating Engine for frontend
app.set('views', path.join(__dirname, '../public/views'));
app.set('view engine', 'ejs');

const publicRoutes = require('../public/routes');
app.use('/', publicRoutes);

/// ##################
app.use('/uploads/:id', (req, res) => {
    res.sendFile(path.join(__dirname, `../uploads/${req.params.id}`));
});
/// #################

// Very last outcome if nothing else is found for specified url
app.use((req, res) => {
    res.status(404);
    res.json({
        status: res.statusCode,
        message: `Not found - ${req.originalUrl}`
    });
});

module.exports = app;