Skip to content

Commit

Permalink
Add ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed May 14, 2024
1 parent c56ffc1 commit 805e86b
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/server.js
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");
});
}

0 comments on commit 805e86b

Please sign in to comment.