-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
37 lines (31 loc) · 1.04 KB
/
app.js
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
37
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import productRouter from './routers/products';
import authRouter from './routers/auth';
import categoryRouter from './routers/categories';
import userRouter from './routers/user';
import slideRouter from './routers/slide';
import routerCart from './routers/cart';
const app = express();
app.use(express.json());
app.use(cors());
// Routing
app.get('/', (req, res) => {
res.send("<h1>Home Page</h1>");
});
app.use('/api', productRouter);
app.use('/api', authRouter);
app.use('/api', categoryRouter);
app.use('/api', userRouter);
app.use('/api', slideRouter);
app.use('/api', routerCart);
const uri = "mongodb+srv://quyetpvph15476:[email protected]/nextjs?retryWrites=true&w=majority";
const db = uri || "mongodb://localhost:27017/nextjs";
mongoose.connect(db)
.then(() => console.log("Connect db thanh cong"))
// Content
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`Server running port ${PORT}`);
})