Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
1
Indexable
Never
const express = require('express');
const cors = require('cors');
const path = require('path');
const user = require('./src/api/user.js');
const admin = require('./src/api/admin.js');
const manageMatch = require('./src/api/match.js');
const manageAppSettings = require('./src/api/appSettings.js');
const manageHighlight = require('./src/api/highlight.js');
const manageFixture = require('./src/api/sportmonk.js');
const managePopular = require('./src/api/popular.js');
const manageNews = require('./src/api/news.js');
const manageContact = require('./src/api/contact.js');
const manageGeneralSetting = require('./src/api/generalSettings.js');
const manageImage = require('./src/api/uploadImage.js');
const webAPIs = require('./src/api/webApi.js');
// const HandleErrors = require('./utils/error-handler')

const corsOptions = {
    origin: ['http://localhost:3000', 'http://localhost:3001', 'http://localhost:1000', 'http://localhost:2000'],
    credentials: true
};

const expressApp = async app => {

    // Middleware to serve static files from the "images" folder
    const imagesFolderPath = path.join(__dirname, 'images');
    app.use('/images', express.static(imagesFolderPath));

    // middleware
    app.use(cors(corsOptions));
    app.use(express.json());
    app.use(express.urlencoded({ extended: true }));

    // Web api
    webAPIs(app);

    // Admin api
    user(app);
    admin(app);
    manageMatch(app);
    manageAppSettings(app);
    manageHighlight(app);
    manageFixture(app);
    managePopular(app);
    manageNews(app);
    manageContact(app);
    manageGeneralSetting(app);
    manageGeneralSetting(app);
    manageImage(app);
    // // error handling
    // app.use(HandleErrors);
};

module.exports = expressApp;