-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
297ca5e
commit e79117e
Showing
21 changed files
with
556 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
LOCAL_DB=mongodb://127.0.0.1:27017/stanki | ||
LOCAL_DB=mongodb://127.0.0.1:27017/stanki | ||
PORT=8080 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import express from 'express'; | ||
import morgan from 'morgan'; | ||
import authRoute from './routes/auth-routes'; | ||
import globalError from './controllers/errors'; | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
app.use(morgan('dev')); | ||
|
||
app.use('/api/v1/auth', authRoute); | ||
app.use('*', (req, res) => | ||
res | ||
.status(404) | ||
.send(`Can't find ${req.method} : ${req.originalUrl} on this server!`), | ||
); | ||
app.use(globalError); | ||
|
||
export default app; |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RequestHandler } from 'express'; | ||
|
||
const signup: RequestHandler = async (req, res, next) => {}; | ||
|
||
export default signup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NextFunction, Response } from 'express'; | ||
|
||
const handleDevErrors = (err: AppError, res: Response, next: NextFunction) => { | ||
res.status(err.statusCode).json({ | ||
status: err.status, | ||
message: err.message, | ||
error: err, | ||
stack: err.stack, | ||
}); | ||
}; | ||
|
||
export default handleDevErrors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
const globalError = ( | ||
err: AppError, | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
res.status(500).json({ | ||
status: 'error', | ||
message: err.message, | ||
error: err, | ||
}); | ||
}; | ||
|
||
export default globalError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NextFunction, Response } from 'express'; | ||
|
||
const handleProdErrors = (err: AppError, res: Response, next: NextFunction) => { | ||
res.status(err.statusCode).json({ | ||
status: err.status, | ||
message: err.message, | ||
error: err, | ||
stack: err.stack, | ||
}); | ||
}; | ||
|
||
export default handleProdErrors; |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Router } from 'express'; | ||
import signup from '../../controllers/auth/signup'; | ||
|
||
const router = Router(); | ||
|
||
router.post('/signup', signup); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AppError extends Error { | ||
public statusCode: number; | ||
public status: string; | ||
public isOperational: boolean; | ||
|
||
constructor(message: string, statusCode: number) { | ||
super(message); | ||
|
||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
this.isOperational = true; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import nodemailer from 'nodemailer'; | ||
|
||
// TODO 1: Implement the sendEmail function | ||
const sendEmail = async (email: string, subject: string, text: string) => { | ||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: process.env.EMAIL, | ||
pass: process.env.EMAIL_PASSWORD, | ||
}, | ||
}); | ||
|
||
await transporter.sendMail({ | ||
from: process.env.EMAIL, | ||
to: email, | ||
subject, | ||
text, | ||
}); | ||
}; | ||
|
||
export default sendEmail; |