-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
45 lines (36 loc) · 1.35 KB
/
server.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
38
39
40
41
42
43
44
45
import 'dotenv/config.js'
import express from 'express'
import path from 'path'
import { fileURLToPath } from 'url'
import logger from 'morgan'
import methodOverride from 'method-override'
import cors from 'cors'
const app = express();
import('./config/database.js')
import { router as profilesRouter } from './routes/profiles.js'
import { router as authRouter } from './routes/auth.js'
import { router as productsRouter } from './routes/products.js'
import { router as shopsRouter } from './routes/shops.js'
import { router as searchRouter } from './routes/search.js'
import { router as recentRouter } from './routes/recent.js'
import { router as reviewRouter } from './routes/reviews.js'
app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.static(path.join(path.dirname(fileURLToPath(import.meta.url)), 'build')));
app.use('/api/profiles', profilesRouter);
app.use('/api/auth', authRouter);
app.use('/api/shops', shopsRouter)
app.use('/api/products', productsRouter)
app.use('/api/search', searchRouter)
app.use('/api/recent', recentRouter)
app.use('/api/reviews', reviewRouter)
app.get("/*", function (req, res) {
res.sendFile(
path.join(path.dirname(fileURLToPath(import.meta.url)), "build", "index.html")
)
})
const port = process.env.PORT || 3001;
app.listen(port, ()=> {
console.log(`Express is listening on port ${port}.`)
});