Introduce env variable for webapp origin

This commit is contained in:
Maciej Ziarkowski 2019-08-22 15:56:04 +01:00
parent a3ab275378
commit 7cc358dcb7
3 changed files with 11 additions and 2 deletions

View File

@ -72,8 +72,7 @@ async function resetPassword(req: express.Request, res: express.Response) {
if(req.body.email != undefined) {
// first stage: send reset token to email address
// this relies on the API being on the same hostname as the frontend
const { origin } = new URL(req.protocol + '://' + req.headers.host);
const origin = getWebAppOrigin();
await passwordResetService.sendPasswordResetToken(req.body.email, origin);
return res.status(202).send({ success: true });
@ -96,6 +95,14 @@ async function resetPassword(req: express.Request, res: express.Response) {
}
}
function getWebAppOrigin() : string {
const origin = process.env.WEBAPP_ORIGIN;
if (origin == undefined) {
throw new Error('WEBAPP_ORIGIN not defined');
}
return origin;
}
export default {
createUser,
getCurrentUser,

View File

@ -25,6 +25,7 @@ module.exports = {
MAIL_SERVER_PORT: 587,
MAIL_SERVER_USER: "mail_username",
MAIL_SERVER_PASSWORD: "longrandompassword",
WEBAPP_ORIGIN: "http://localhost:3000",
}
}
]

View File

@ -22,6 +22,7 @@ module.exports = {
MAIL_SERVER_PORT: 587,
MAIL_SERVER_USER: "mail_username",
MAIL_SERVER_PASSWORD: "longrandompassword",
WEBAPP_ORIGIN: "https://beta.colouring.london",
}
}
]