2023-09-06 16:55:43 +00:00
|
|
|
import express from "express"
|
|
|
|
import pinoHTTP from 'pino-http'
|
|
|
|
import logger from "./logger.mjs";
|
|
|
|
import bodyParser from "body-parser";
|
|
|
|
import { Data } from "./objects/Data.mjs";
|
|
|
|
import { db } from "./db.mjs";
|
|
|
|
import { getEndpoints } from "./objects/Endpoints.mjs";
|
|
|
|
import cors from 'cors'
|
2023-09-06 16:26:15 +00:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
const port = 4000
|
2023-09-06 16:55:43 +00:00
|
|
|
const corsOptions={
|
|
|
|
origin: ['http://localhost:5173']
|
|
|
|
}
|
|
|
|
app.use(cors())
|
|
|
|
app.use(pinoHTTP({logger}))
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
|
|
|
|
|
2023-09-06 16:26:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
const data = new Data(db)
|
|
|
|
await data.init()
|
2023-09-06 16:55:43 +00:00
|
|
|
|
2023-09-06 16:26:15 +00:00
|
|
|
app.use('/api',getEndpoints(data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.listen(port, (err) => {
|
|
|
|
if (err) logger.error(err);
|
|
|
|
logger.info("Server listening on PORT " + port)
|
|
|
|
})
|
|
|
|
|
|
|
|
export default app
|