-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (34 loc) · 1.05 KB
/
Copy pathserver.js
File metadata and controls
43 lines (34 loc) · 1.05 KB
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
import path from 'path'
import express from 'express'
import cookieParser from 'cookie-parser'
import cors from 'cors'
import { logger } from './services/logger.service.js'
import { toyRoutes } from './api/toy/toy.route.js'
import { userRoutes } from './api/user/user.routes.js'
import { authRoutes } from './api/auth/auth.routes.js'
const app = express()
// Express Config
app.use(express.static('public'))
app.use(cookieParser())
app.use(express.json())
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.resolve('public')))
} else {
const corsOptions = {
origin: ['http://127.0.0.1:5173', 'http://localhost:5173'],
credentials: true
}
app.use(cors(corsOptions))
}
// Routes
app.use('/api/toy', toyRoutes)
app.use('/api/user', userRoutes)
app.use('/api/auth', authRoutes)
// Fallback route
app.get('/*all', (req, res) => {
res.sendFile(path.resolve('public/index.html'))
})
const port = process.env.PORT || 3030
app.listen(port, () => {
logger.info(`Server is running on port: http://127.0.0.1:${port}`)
})