Here is the startup file which can be used for the startup file
import express from 'express'
import payload from 'payload'
import path from 'path'
import nodemailerSendgrid from 'nodemailer-sendgrid'
const sendGridAPIKey = process.env.SENDGRIDAPI_KEY
require('dotenv').config({
path: path.resolve(__dirname, '../.env'),
})
const app = express()
const PORT = process.env.PORT || 8000
// Redirect root to Admin panel
app.get('/', (, res) => {
res.redirect('/admin')
})
const start = async () => {
// Initialize Payload
await payload.init({
secret: process.env.PAYLOAD_SECRET || '',
express: app,
...(sendGridAPIKey
? {
email: {
fromName: '',
fromAddress: '',
transportOptions: nodemailerSendgrid({
apiKey: sendGridAPIKey,
}),
},
}
: {}),
onInit: async () => {
payload.logger.info(Payload Admin URL: ${payload.getAdminURL()})
},
})
// Add your own express routes here
app.listen(process.env.PORT, async () => {
payload.logger.info(Server listening on port ${PORT})
})
}
void start()