Skip to content

Commit

Permalink
env example added
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanRaja committed Jul 31, 2022
1 parent 123ef63 commit 0794f86
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APP_BASE_URL='http://localhost:3000'
MONGODB_URI=
SMTP_HOST=
SMTP_POST=
MAIL_USER=
MAIL_PASSWORD=
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,4 @@ dist
.pnp.*

# uploads
/uploads

# config file
config.js
/uploads
3 changes: 2 additions & 1 deletion config/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose')
require('dotenv').config()

const mongoURI = 'mongodb://localhost:27017'
const mongoURI = process.env.MONGODB_URI


// Connecting the database
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ app.use('/files', require("./routes/show"))
app.use('/file/download', require('./routes/download'))

app.listen(port, () => {
console.log(`Example app listening on port http://localhost:${port}`)
console.log(`Example app listening on port ${port}`)
})
6 changes: 3 additions & 3 deletions routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const path = require('path')
const multer = require('multer')
const File = require('../models/File')
const { v4: uuid4 } = require('uuid')
const config = require("../config")
const sendEmail = require('../services/emailService')
require('dotenv').config()

const storage = multer.diskStorage({
destination: (req, file, cb) => {
Expand Down Expand Up @@ -41,7 +41,7 @@ router.post('/', (req, res) => {

const response = await fileUpload.save()

return res.send({ filePath: `${config.base_URL}/files/${response.uuid}` })
return res.send({ filePath: `${process.env.APP_BASE_URL}/files/${response.uuid}` })
})
})

Expand Down Expand Up @@ -70,7 +70,7 @@ router.post('/send', async (req, res) => {
text: `${emailFrom} has shared an email with you.`,
html: require('../services/emailTemplate')( {
text: `${emailFrom} has shared an email with you.`,
downloadLink: `${config.base_URL}/file/download/${file.uuid}`,
downloadLink: `${process.env.APP_BASE_URL}/file/download/${file.uuid}`,
size: file.size,
expires: "24 hours"
} )
Expand Down
4 changes: 2 additions & 2 deletions routes/show.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const router = require('express').Router()
const File = require('../models/File')
const config = require('../config')
require('dotenv').config()

router.get('/:uuid', async (req, res) => {
try {
Expand All @@ -14,7 +14,7 @@ router.get('/:uuid', async (req, res) => {
uuid: file.uuid,
filename: file.filename,
fileSize: file.size,
downloadLink: `${config.base_URL}/file/download/${file.uuid}`
downloadLink: `${process.env.APP_BASE_URL}/file/download/${file.uuid}`
})
}
catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions services/emailService.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const mailer = require('nodemailer')
const config = require('../config')
require('dotenv').config()

const sendEmail = async ({ from, to, subject, text, html }) => {
const transport = mailer.createTransport({
host: config.SMTP_HOST,
port: config.SMTP_POST,
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: false,
auth: {
user: config.MAIL_USER,
pass: config.MAIL_PASSWORD
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASSWORD
}
})

Expand Down

0 comments on commit 0794f86

Please sign in to comment.