-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafter.txt
36 lines (30 loc) · 945 Bytes
/
after.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import express from "express";
import { PORT, mongoDBURL } from "./config.js";
import mongoose from "mongoose";
import bookRoute from './routes/bookRoutes.js';
import cors from "cors";
const app = express();
app.use(express.json()); // to recognize request body
// Configure CORS
const corsOptions = {
origin: 'http://localhost:5173',
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type'],
optionsSuccessStatus: 200,
};
app.use(cors(corsOptions));
app.get("/", (request, response) => {
response.status(234).send("Welcome to Book Store System");
});
app.use('/books', bookRoute);
mongoose
.connect(mongoDBURL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log('App connected to database');
app.listen(PORT, () => {
console.log(`App is listening on PORT ${PORT}`);
});
})
.catch((error) => {
console.error('Database connection error:', error);
});