From 9060ffbcc0657bc5de72481e58df56f0b91f8f5f Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 22 Jul 2022 01:57:37 +0000 Subject: [PATCH] Add config options for mongo auth and server port --- .env.example | 6 ++++++ .gitignore | 3 ++- src/payload.config.ts | 2 +- src/server.ts | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d26aced --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +PAYLOAD_SECRET= +MONGODB_HOST=localhost +MONGODB_DB=summer-dci +MONGODB_USER= +MONGODB_PASS= +LISTEN_PORT=3000 diff --git a/.gitignore b/.gitignore index 3c440c8..e2f4eb6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ dist/ build/ .env src/media -.eslintcache \ No newline at end of file +.eslintcache +.*.swp diff --git a/src/payload.config.ts b/src/payload.config.ts index 943ee99..71aefdf 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -4,7 +4,7 @@ import path from 'path'; import Users from './collections/Users'; export default buildConfig({ - serverURL: 'http://localhost:3001', + serverURL: 'https://summer.mattfidd.rocks', admin: { user: Users.slug }, diff --git a/src/server.ts b/src/server.ts index ec710e1..769a78c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,13 +7,25 @@ dotenv.config(); const app = express(); +const generateMongoURI = (): string => { + return ( + 'mongodb://' + + (process.env.MONGODB_USER ? + `${process.env.MONGODB_USER}:${process.env.MONGODB_PASS}@` : + '' + ) + + `${process.env.MONGODB_HOST}/` + + process.env.MONGODB_DB + ); +}; + payload.init({ secret: process.env.PAYLOAD_SECRET, - mongoURL: process.env.MONGODB_URI, + mongoURL: generateMongoURI(), express: app, onInit: () => { payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`); } }); -app.listen(3001); +app.listen(process.env.LISTEN_PORT);