-
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
77a78ed
commit 02e61a0
Showing
7 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ DB_USER= | |
DB_PASSWORD= | ||
SENDGRID_API_KEY= | ||
SENDGRID_VERIFIED_SENDER= | ||
FRONT_END_URL= | ||
FRONT_END_URL= | ||
WEBHOOK_SECRET= |
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,15 @@ | ||
module.exports = { | ||
apps: [ | ||
{ | ||
name: "wgp-api", | ||
script: "./index.js", | ||
watch: true, | ||
env: { | ||
NODE_ENV: "dev", | ||
}, | ||
env_production: { | ||
NODE_ENV: "prod", | ||
}, | ||
}, | ||
], | ||
}; |
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
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,24 @@ | ||
const { WEBHOOK_SECRET } = process.env; | ||
|
||
let crypto; | ||
try { | ||
crypto = require("node:crypto"); | ||
} catch (err) { | ||
console.error("crypto support is disabled!"); | ||
} | ||
|
||
const validateRequestSecret = (request) => { | ||
const expectedSignature = | ||
"sha1=" + | ||
crypto | ||
.createHmac("sha1", WEBHOOK_SECRET) | ||
.update(JSON.stringify(request.body)) | ||
.digest("hex"); | ||
const signature = request.headers["x-hub-signature"]; | ||
console.log({ expectedSignature, signature }); | ||
if (signature !== expectedSignature) { | ||
throw new Error("Invalid signature."); | ||
} | ||
}; | ||
|
||
module.exports = { validateRequestSecret }; |
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,32 @@ | ||
const { execSync } = require("child_process"); | ||
const express = require("express"); | ||
const { validateRequestSecret } = require("../utils/secrets"); | ||
|
||
const router = express.Router(); | ||
|
||
const IS_DEV = process.env.NODE_ENV === "dev"; | ||
|
||
router.post("/release", async (req, res) => { | ||
let sentResponse = false; | ||
try { | ||
console.log("VALIDATING HOOK SECRET"); | ||
validateRequestSecret(req); | ||
|
||
console.log("PULLING FROM MAIN"); | ||
await execSync("git pull origin main"); | ||
|
||
console.log("SENDING SUCCESS"); | ||
res.sendStatus(204); | ||
sentResponse = true; | ||
|
||
console.log("RESTARTING PM2 SERVICE"); | ||
await execSync(`pm2 restart wgp-api ${IS_DEV ? "" : "--env production"}`); | ||
} catch (err) { | ||
console.error(err); | ||
if (!sentResponse) { | ||
return res.status(500).send(err.message); | ||
} | ||
} | ||
}); | ||
|
||
module.exports = router; |
02e61a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
wargameplan-frontend – ./
wargameplan-frontend-git-main-mikosramek.vercel.app
wargameplan-frontend-mikosramek.vercel.app
wargameplan-frontend.vercel.app
wargameplanner.com
www.wargameplanner.com