6bb4719e99
deploy to danak / build_and_deploy (push) Has been cancelled
Replace self-proxy with direct SSR baseURL, rewrite blog post pagination with async/await, pin mongoose-paginate-v2, and add API error logging. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
const database = require('./database')
|
|
const fileUpload = require('express-fileupload')
|
|
const {isUser, isAdmin} = require('./authentication')
|
|
const bodyParser = require('body-parser')
|
|
const cronJobs = require('./plugins/cronJobs')
|
|
const {createAdmins} = require('./plugins/privateAdmin')
|
|
|
|
// Create express instnace
|
|
const app = express()
|
|
cronJobs()
|
|
createAdmins()
|
|
// 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 Public = require('./routes/public')
|
|
const admin = require('./routes/admin')
|
|
const auth = require('./routes/auth')
|
|
|
|
// Use API Routes
|
|
app.use('/public', Public)
|
|
app.use('/auth', auth)
|
|
app.use('/admin', isAdmin, admin)
|
|
|
|
app.get('/health', (req, res) => {
|
|
res.json({ ok: true })
|
|
})
|
|
|
|
app.use((err, req, res, next) => {
|
|
console.error('Express error:', req.method, req.originalUrl, err?.message || err)
|
|
res.status(500).json({ message: err?.message || 'Internal Server Error' })
|
|
})
|
|
|
|
// Export the server middleware
|
|
module.exports = {
|
|
path: '/api',
|
|
handler: app
|
|
}
|