app.js 1.21 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import express from 'express';
kusang96's avatar
dd    
kusang96 committed
2
import fs from 'fs';
kusang96's avatar
kusang96 committed
3
4
import connectDb from './schemas/index.js';
import categoryRouter from "./routes/category.routes.js";
Kim, Subin's avatar
Kim, Subin committed
5
import userRouter from "./routes/user.routes.js";
Jiwon Yoon's avatar
Jiwon Yoon committed
6
import productRouter from './routes/product.routes.js';
7
import cartRouter from './routes/cart.routes.js';
Jiwon Yoon's avatar
Jiwon Yoon committed
8
9
10
import path from 'path'
import kakaopayRoutes from './routes/kakaopay.routes.js'
import config from './config.js'
이재연's avatar
이재연 committed
11
import authRouter from './routes/auth.routes.js'
Jiwon Yoon's avatar
Jiwon Yoon committed
12
import orderRouter from './routes/order.routes.js'
Jiwon Yoon's avatar
Jiwon Yoon committed
13
import cors from 'cors'
Kim, Subin's avatar
Kim, Subin committed
14

kusang96's avatar
dd    
kusang96 committed
15
16
17
18
19
20
fs.readdir('uploads', (error) => {
  if (error) {
      fs.mkdirSync('uploads');
  }
})

Kim, Subin's avatar
Kim, Subin committed
21
22
connectDb()

Kim, Subin's avatar
Kim, Subin committed
23
const app = express();
kusang96's avatar
kusang96 committed
24
app.use(express.json())
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
app.use(cors())
app.use(express.static(path.join(process.cwd(), 'dist')))
// app.use(bodyParser.urlencoded({ extended: true }))
Jiwon Yoon's avatar
qwr    
Jiwon Yoon committed
28
app.use('/images', express.static('uploads/'))
Kim, Subin's avatar
Kim, Subin committed
29

Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
// app.use('/', indexRouter);
app.use('/', kakaopayRoutes)
kusang96's avatar
0115    
kusang96 committed
32
app.use('/api/categories',categoryRouter)
이재연's avatar
이재연 committed
33
app.use('/api/users',userRouter)
이재연's avatar
이재연 committed
34
app.use('/api/auth',authRouter)
kusang96's avatar
kusang96 committed
35
app.use('/api/product', productRouter)
Jiwon Yoon's avatar
qwr    
Jiwon Yoon committed
36
app.use('/api/cart', cartRouter)
Jiwon Yoon's avatar
Jiwon Yoon committed
37
app.use('/api/order', orderRouter)
Kim, Subin's avatar
Kim, Subin committed
38

Jiwon Yoon's avatar
Jiwon Yoon committed
39
40
41
app.listen(config.port, () => {
  console.info('Server started on port %s.', config.port)
})
Kim, Subin's avatar
Kim, Subin committed
42