ShiftSync/api/server.js

45 lines
No EOL
1 KiB
JavaScript

import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import { medicationRouter } from './services/medications/index.js';
import { shiftRunQuery } from './services/shiftConnection.js';
dotenv.config();
const app = express();
const corsOptions = {
origin: [
"http://localhost:5173",
"https://shift-dev.code-catalyst.com",
"https://shift.code-catalyst.com"
]
};
app.use(cors(corsOptions));
app.use(express.json({ limit: '10mb' }));
app.use(express.json());
const apiRouter = express.Router();
apiRouter.use('/medication', medicationRouter);
app.get("/api", (req, res) => {
res.json('Welcome to Shift Sync API');
});
app.use('/api', apiRouter);
app.get('/db-health', async (req, res) => {
try {
const result = await shiftRunQuery('SELECT NOW()');
res.json({ connected: true, time: result.rows[0].now });
} catch (err) {
console.error(err);
res.status(500).json({ connected: false, error: err.message });
}
});
app.listen(5172, () => {
console.log('Server Started on port 5172');
});