Skip to content

Commit

Permalink
redis host and api key
Browse files Browse the repository at this point in the history
  • Loading branch information
gotham13 committed Apr 8, 2024
1 parent 8592da8 commit 3012ffa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
node_modules/
package-lock.json
cert/
cert/
dist/
4 changes: 0 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ app
.use(bodyParser.json({ limit: "100mb" }))
.use(queueRoute);

app.get("/", (req: Request, res: Response) => {
res.send("Logstash Server Reading");
});

app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
handleError(err, res);
});
Expand Down
4 changes: 4 additions & 0 deletions src/routes/queue-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ setInterval(async () => {

router.post("/log", async (req: Request, res: Response) => {
try {
let apiKey = req.headers["x-api-key"];
if (apiKey != process.env.API_KEY) {
throw new Error("Invalid Api Key");
}
const { logs } = req.body;
await queue.addBulk(
logs.map((log: logType) => ({
Expand Down
13 changes: 12 additions & 1 deletion src/utils/queue-client.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
import { Queue } from "bullmq";
export default new Queue("logs");
export default new Queue("logs", {
connection: {
host: process.env.REDIS_HOST,
username: process.env.REDIS_USERNAME,
password: process.env.REDIS_PASSWORD,
port: process.env.REDIS_PORT ? parseInt(process.env.REDIS_PORT) : undefined,
db: process.env.REDIS_DB_INDEX
? parseInt(process.env.REDIS_DB_INDEX)
: undefined,
},
prefix: process.env.QUEUE_PREFIX,
});

0 comments on commit 3012ffa

Please sign in to comment.