-
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
c56ffc1
commit 805e86b
Showing
1 changed file
with
25 additions
and
11 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,32 +1,46 @@ | ||
import Express from 'express'; | ||
import https from 'https'; | ||
import fs from 'fs'; | ||
|
||
const SERVER_CRT = process.env.SERVER_CRT; | ||
const SERVER_KEY = process.env.SERVER_KEY; | ||
|
||
const app = Express(); | ||
app.use(Express.json()); | ||
|
||
let EVENTS=[]; | ||
let EVENTS = []; | ||
|
||
app.post("/post", (req, res) => { | ||
app.post("/post", (req, res) => { | ||
const event = req.body; | ||
const secret=req.query.secret; | ||
const secret = req.query.secret; | ||
EVENTS.push({ | ||
event: event, | ||
timestamp: new Date(), | ||
secret: secret | ||
}); | ||
res.json({status: "ok"}); | ||
res.json({ status: "ok" }); | ||
}); | ||
|
||
app.get("/get", (req, res) => { | ||
const secret=req.query.secret; | ||
EVENTS=EVENTS.filter((event) => { | ||
return new Date() - event.timestamp < 1000*60*60; | ||
const secret = req.query.secret; | ||
EVENTS = EVENTS.filter((event) => { | ||
return new Date() - event.timestamp < 1000 * 60 * 60; | ||
}); | ||
res.json(EVENTS.filter((event) => { | ||
return event.secret === secret; | ||
}).map((event) => event.event)); | ||
}); | ||
|
||
|
||
app.listen(3000, () => { | ||
console.log("Server is running on port 3000"); | ||
}); | ||
if (SERVER_CRT && SERVER_KEY) { | ||
const options = { | ||
key: fs.readFileSync(SERVER_KEY), | ||
cert: fs.readFileSync(SERVER_CRT) | ||
}; | ||
https.createServer(options, app).listen(3000, () => { | ||
console.log("HTTPS Server is running on port 3000"); | ||
}); | ||
} else { | ||
app.listen(3000, () => { | ||
console.log("HTTP Server is running on port 3000"); | ||
}); | ||
} |