Skip to content

Commit f8fc79d

Browse files
committed
Initial commit
0 parents  commit f8fc79d

7 files changed

Lines changed: 200 additions & 0 deletions

File tree

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ko_fi: alphasec
2+
buy_me_a_coffee: alphasec

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm"
9+
directory: "/"
10+
schedule:
11+
interval: "monthly"
12+
allow:
13+
- dependency-type: "all"

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Alphasec
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# webhook-server
2+
A sample webhook server using Node.js and Express. The server listens on port 3000, and exposes two endpoints `/webhook-1` and `/webhook-2`.
3+
4+
For a detailed guide to webhook servers, see [this](https://alphasec.io/getting-started-with-webhooks-part-1-webhook-servers/) post. To deploy on [Railway](https://railway.app/?referralCode=alphasec) using a one-click template, click the button below.
5+
6+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/WJuLbj?referralCode=alphasec)

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "webhook-server",
3+
"version": "1.0.0",
4+
"description": "A sample webhook server using Node.js and Express.",
5+
"main": "server.js",
6+
"author": "alphasec",
7+
"license": "MIT",
8+
"dependencies": {
9+
"express": "^4.18.2"
10+
},
11+
"scripts": {
12+
"start": "node server.js"
13+
}
14+
}

server.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const express = require("express");
2+
3+
// Create an Express app and listen for incoming requests on port 3000
4+
const app = express();
5+
const router = express.Router();
6+
const port = process.env.PORT || 3000;
7+
8+
// Use middleware to parse incoming requests with JSON and URL-encoded payloads
9+
app.use(express.json());
10+
app.use(express.urlencoded());
11+
12+
// Error handling middleware
13+
app.use((err, req, res, next) => {
14+
console.error(err.stack);
15+
res.status(500).send("Internal Server Error");
16+
});
17+
18+
// Handle GET requests to the root URL
19+
router.get("/", (req, res) => {
20+
res.send("Welcome to the Webhook Server!");
21+
});
22+
23+
// Handle POST requests to specific URLs i.e. webhook endpoints
24+
router.post("/webhook-1", (req, res) => {
25+
console.log(req.body);
26+
res.send("Webhook 1 successfully received.");
27+
});
28+
29+
router.post("/webhook-2", (req, res) => {
30+
console.log(req.body);
31+
res.send("Webhook 2 successfully received.");
32+
});
33+
34+
// Mount the router middleware
35+
app.use(router);
36+
37+
// Start the server and listen for incoming connections
38+
app.listen(port, () => {
39+
console.log(`Server running at https://localhost:${port}/`);
40+
});

0 commit comments

Comments
 (0)