const express = require('express')
const db = require('./db')
const fileUpload = require('express-fileupload')
const config = require('./config')
require('dotenv').config({path: __dirname+'/.env'})
// Create express instnace
const app = express()

// Init body-parser options (inbuilt with express)
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(fileUpload())


// Require & Import API routes
const Private = require('./routes/private')
const Public = require('./routes/public')
const auth = require('./routes/auth')

// Use API Routes
app.use('/private', config.isAdmin, Private)
app.use('/auth', auth)
app.use('/public', Public)


// Export the server middleware
module.exports = {
   path: '/api',
   handler: app
}
