Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MONGODB_USER=root
MONGODB_PASSWORD=pass
MONGODB_DATABASE=autorizz
MONGODB_LOCAL_PORT=27017
MONGODB_DOCKER_PORT=27017

NODE_LOCAL_PORT=5000
NODE_DOCKER_PORT=5000
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:alpine
WORKDIR /app

COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@
2. Open Terminal in the app folder
3. Run `npm start` or `nodemon start` (if nodemon is preinstalled)
4. Launch client app in `localhost:5000`
4. Launch admin app in `localhost:5000/admin`
5. Launch admin app in `localhost:5000/admin`


#### Docker
1. Create a `.env` file, and copy the content from `.env.example`.
2. Run following command to start MongoDB and Node server.
```
docker-compose up
```
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const app = express();
//Connecting to Mongodb
const db = async () => {
try {
const conn = await mongoose.connect('mongodb://localhost:27017/autorizz', {
const connString = isDocker() ?
`mongodb://${process.env.MONGODB_USER}:${process.env.MONGODB_PASSWORD}
@mongodb:${process.env.MONGODB_DOCKER_PORT}/${process.env.MONGODB_DATABASE}?authSource=admin`:
'mongodb://localhost:27017/autorizz';
await mongoose.connect(connString, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
Expand Down
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.8"

services:
mongodb:
image: mongo:latest
restart: unless-stopped
env_file: ./.env
environment:
- MONGO_INITDB_ROOT_USERNAME=$MONGODB_USER
- MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD
ports:
- $MONGODB_LOCAL_PORT:$MONGODB_DOCKER_PORT
volumes:
- db:/data/db
app:
depends_on:
- mongodb
build: .
restart: unless-stopped
env_file: ./.env
ports:
- $NODE_LOCAL_PORT:$NODE_DOCKER_PORT
environment:
- DB_HOST=mongodb
- DB_USER=$MONGODB_USER
- DB_PASSWORD=$MONGODB_PASSWORD
- DB_NAME=$MONGODB_DATABASE
- DB_PORT=$MONGODB_DOCKER_PORT
stdin_open: true
tty: true

volumes:
db:
Loading