Feature/api paramyxrx (#25)

* Update .gitignore

* Finalize server and add endpoints for paramyx app

* Update server.js

* Add middleware

* fix error

* Update auth.js

* add logs

* log

* Remove Console Logs
This commit is contained in:
Matt DiMeglio 2026-01-18 01:26:01 -05:00 committed by GitHub
parent 8cebefe5a6
commit 6ef7d89de3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 3 deletions

22
api/middleware/auth.js Normal file
View file

@ -0,0 +1,22 @@
export const validateMedicationApiKey = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token || token !== process.env.MEDICATION_API_KEY) {
console.log('MEDICATION - User entered an Invalid token: ', token);
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
next();
};
export const validateShiftSyncApiKey = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token || token !== process.env.SHIFTSYNC_API_KEY) {
console.log('SHIFT - User entered an Invalid token: ', token);
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
next();
};

View file

@ -2,7 +2,9 @@ import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import { medicationRouter } from './services/medications/index.js';
import { shiftsRouter } from './services/shifts/index.js';
import { shiftRunQuery } from './services/shiftConnection.js';
import { validateMedicationApiKey, validateShiftSyncApiKey } from './middleware/auth.js';
dotenv.config();
const app = express();
@ -22,7 +24,11 @@ app.use(express.json());
const apiRouter = express.Router();
apiRouter.use('/medication', medicationRouter);
// ParamyxRx Router (/api/medication)
apiRouter.use('/medication', validateMedicationApiKey, medicationRouter);
// ShiftSync Router (/api/shifts)
apiRouter.use('/shifts', validateShiftSyncApiKey, shiftsRouter);
app.get("/api", (req, res) => {
res.json('Welcome to Shift Sync API');
@ -30,7 +36,7 @@ app.get("/api", (req, res) => {
app.use('/api', apiRouter);
app.get('/db-health', async (req, res) => {
app.get('/api/db-health', async (req, res) => {
try {
const result = await shiftRunQuery('SELECT NOW()');
res.json({ connected: true, time: result.rows[0].now });

View file

@ -16,7 +16,7 @@ const getBaseMedications = async () => {
const dataResp = medicationHelpers.getBaseMedications();
return dataResp;
} catch (err) {
console.log('GET MEDICATIONS ERROR: ', err);
console.log('GET BASE MEDICATIONS ERROR: ', err);
throw err;
}
}

View file

@ -0,0 +1,3 @@
import express from 'express';
export const shiftsRouter = express.Router();