mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
33 lines
844 B
TypeScript
33 lines
844 B
TypeScript
import path from 'path'
|
|
import express from 'express'
|
|
import morgan from 'morgan'
|
|
import dotenv from 'dotenv'
|
|
import cors from 'cors'
|
|
|
|
import webRouter from './routes/web'
|
|
import apiRouter from './routes/api'
|
|
import { getWebBuildFolderPath } from './utils'
|
|
import { connectDB } from './routes/api/auth'
|
|
|
|
dotenv.config()
|
|
|
|
const app = express()
|
|
|
|
const { MODE } = process.env
|
|
if (MODE?.trim() !== 'server') {
|
|
console.log('All CORS Requests are enabled')
|
|
app.use(cors({ credentials: true, origin: 'http://localhost:3000' }))
|
|
}
|
|
|
|
app.use(express.json({ limit: '50mb' }))
|
|
app.use(morgan('tiny'))
|
|
app.use(express.static(path.join(__dirname, '../public')))
|
|
|
|
app.use('/', webRouter)
|
|
app.use('/SASjsApi', apiRouter)
|
|
app.use(express.json({ limit: '50mb' }))
|
|
|
|
app.use(express.static(getWebBuildFolderPath()))
|
|
|
|
export default connectDB().then(() => app)
|