Files
payload/templates/website/src/server.default.ts
Elliot DeNolf 25d20cf87b feat: 2.0 template updates (#3488)
* feat: update templates to 2.0 and support create-payload-app

* chore: rich text updates

* chore(templates): remove mongoURL

* chore: migrates rich text fields in website

* chore: manually aliases dotenv in templates

* chore: installs new beta in website template

* chore: type issues

* chore (template): add alias for fs to website template

* chore: more template updates

---------

Co-authored-by: James <james@trbl.design>
Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
2023-10-08 23:23:51 -04:00

45 lines
1014 B
TypeScript

import dotenv from 'dotenv'
import path from 'path'
// This file is used to replace `server.ts` when ejecting i.e. `yarn eject`
// See `../eject.ts` for exact details on how this file is used
// See `./README.md#eject` for more information
dotenv.config({
path: path.resolve(__dirname, '../.env'),
})
import express from 'express'
import payload from 'payload'
import { seed } from './payload/seed'
const app = express()
const PORT = process.env.PORT || 3000
// Redirect root to the admin panel
app.get('/', (_, res) => {
res.redirect('/admin')
})
const start = async (): Promise<void> => {
await payload.init({
secret: process.env.PAYLOAD_SECRET || '',
express: app,
onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
},
})
if (process.env.PAYLOAD_SEED === 'true') {
await seed(payload)
process.exit()
}
app.listen(PORT, async () => {
payload.logger.info(`App URL: ${process.env.PAYLOAD_PUBLIC_SERVER_URL}`)
})
}
start()