chore: revert #1794 for now until permanent init architecture is established

This commit is contained in:
James
2023-01-11 09:32:44 -05:00
parent 96002dbda5
commit 047efe02ff
7 changed files with 58 additions and 36 deletions

View File

@@ -25,25 +25,24 @@ payload.init({
secret: 'PAYLOAD_SECRET_KEY',
mongoURL: 'mongodb://localhost/payload',
express: app,
onInit: async () => {
const router = express.Router();
});
router.use(payload.authenticate); // highlight-line
const router = express.Router();
router.get('/', (req, res) => {
if (req.user) {
return res.send(`Authenticated successfully as ${req.user.email}.`);
}
router.use(payload.authenticate); // highlight-line
return res.send('Not authenticated');
});
router.get('/', (req, res) => {
if (req.user) {
return res.send(`Authenticated successfully as ${req.user.email}.`);
}
app.use('/some-route-here', router);
return res.send('Not authenticated');
});
app.listen(3000, async () => {
payload.logger.info(`listening on ${3000}...`);
});
},
app.use('/some-route-here', router);
app.listen(3000, async () => {
payload.logger.info(`listening on ${3000}...`);
});
```

View File

@@ -66,7 +66,7 @@ app.listen(3000, async () => {
});
```
This server doesn't do anything just yet. But, after you have this in place, we can initialize Payload via its `init()` method, which accepts a small set of arguments to tell it how to operate. For a full list of `init` arguments, please consult the [main configuration](/docs/configuration/overview) docs.
This server doesn't do anything just yet. But, after you have this in place, we can initialize Payload via its `init()` method, which accepts a small set of arguments to tell it how to operate. For a full list of `init` arguments, please consult the [main configuration](/docs/configuration/overview#init) docs.
To initialize Payload, update your `server.js` file to reflect the following code:
@@ -80,13 +80,12 @@ payload.init({
secret: 'SECRET_KEY',
mongoURL: 'mongodb://localhost/payload',
express: app,
onInit: () => {
app.listen(3000, async () => {
console.log('Express is now listening for incoming connections on port 3000.')
});
}
})
app.listen(3000, async () => {
console.log('Express is now listening for incoming connections on port 3000.')
});
```
Here is a list of all properties available to pass through `payload.init`: