- Added the base data structure for the new database - Added the new routes for the new database - Reworked the users endpoints
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import cors from 'cors';
|
|
import logger from 'morgan';
|
|
import express from 'express';
|
|
import cookieParser from 'cookie-parser';
|
|
|
|
import { log } from './modules/logManager';
|
|
import { speedLimiter, checkSystemLoad } from './modules/requestHandler';
|
|
|
|
import testRouter from './routes/test';
|
|
import usersRouter from './routes/users';
|
|
import doctorsRouter from './routes/doctors';
|
|
import patientsRouter from './routes/patients';
|
|
import companiesRouter from './routes/companies';
|
|
import hospitalsRouter from './routes/hospitals';
|
|
|
|
// create logs directory if it doesn't exist
|
|
const logsDir = path.join(import.meta.dir, 'logs');
|
|
if (!fs.existsSync(logsDir)) fs.mkdirSync(logsDir);
|
|
|
|
const app = express();
|
|
app.set('trust proxy', 1);
|
|
|
|
app.use(express.json());
|
|
app.use(cookieParser());
|
|
app.use(speedLimiter);
|
|
app.use(checkSystemLoad);
|
|
app.use(logger('dev'));
|
|
app.use(logger('combined', { stream: fs.createWriteStream(path.join(import.meta.dir, 'logs/access.log'), { flags: 'a' }) }));
|
|
app.use(cors({
|
|
origin: '*',
|
|
}));
|
|
|
|
app.use(express.static('public'));
|
|
|
|
// routes
|
|
app.use('/api/test', testRouter);
|
|
app.use('/api/users', usersRouter);
|
|
app.use('/api/doctors', doctorsRouter);
|
|
app.use('/api/patients', patientsRouter);
|
|
app.use('/api/companies', companiesRouter);
|
|
app.use('/api/hospitals', hospitalsRouter);
|
|
|
|
// run the API
|
|
app.listen(process.env.PORT, async () => {
|
|
log(`running at port ${process.env.PORT}`);
|
|
});
|
|
|
|
// test
|
|
// import { post } from './modules/fetcher';
|
|
// post('http://127.0.0.1:1109/users/login', { 'usernameOrEmail':'foo', 'password':'bar' }).then(res => console.log(res));
|