Files
payloadcms/test/devServer.ts
Christian Schurr 82961767e3 feat!: enforces payload.init is async
* Run connectMongoose before starting payload init

* - reverted changes
- added deprecated to init
- docs: changed all payload.init to payload.initAsync
- changed all internal init calls

* forgotten inits in docs

* reverted back - removed init and renamed initAsync to init
2023-01-09 11:24:22 -05:00

38 lines
895 B
TypeScript

import express from 'express';
import { v4 as uuid } from 'uuid';
import payload from '../src';
const expressApp = express();
const init = async () => {
await payload.init({
secret: uuid(),
mongoURL: process.env.MONGO_URL || 'mongodb://localhost/payload',
express: expressApp,
email: {
logMockCredentials: true,
fromName: 'Payload',
fromAddress: 'hello@payloadcms.com',
},
onInit: async (app) => {
app.logger.info('Payload Dev Server Initialized');
},
});
// Redirect root to Admin panel
expressApp.get('/', (_, res) => {
res.redirect('/admin');
});
const externalRouter = express.Router();
externalRouter.use(payload.authenticate);
expressApp.listen(3000, async () => {
payload.logger.info(`Admin URL on ${payload.getAdminURL()}`);
payload.logger.info(`API URL on ${payload.getAPIURL()}`);
});
};
init();