Skip to content

Commit

Permalink
feat: middleware for optional api-key
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Feb 28, 2022
1 parent 6ab6bae commit 001c4e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(fileUpload());

app.use(function (req, res, next) {
if (process.env.API_KEY) {
const apikey = req.header('x-api-key');
if (process.env.API_KEY === apikey) {
next();
} else {
res.status(403).json({ message: 'API key not found' });
}
} else {
next();
}
});

app.use('/v1', V1Router);

sequelize.authenticate().then(() => console.log('Connected to database'));
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-audit-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const task = new Task('sync-audit', async () => {
});

const job = new SimpleIntervalJob(
{ minutes: 5, runImmediately: true },
{ seconds: 30, runImmediately: true },
task,
'sync-audit',
);
Expand Down

0 comments on commit 001c4e3

Please sign in to comment.