product.routes.js 921 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import express from "express";
kusang96's avatar
kusang96 committed
2
3
import path from 'path';
import multer from 'multer';
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import productCtrl from '../controllers/product.controller.js';
5
import fs from 'fs'
Jiwon Yoon's avatar
Jiwon Yoon committed
6

kusang96's avatar
kusang96 committed
7
8
// process.cwd() + '/client/public/image'

Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
const router = express.Router()

11
12
13
14
15
16
17
18
19
20
fs.readdir('uploads', (error, data) => {
    if (error) {
        fs.mkdirSync('uploads');
        if (data == undefined) {
          fs.mkdirSync('/main')
          fs.mkdirSync('/detail')
        }
    } else console.log("else data",data)
  })

kusang96's avatar
kusang96 committed
21
22
23
24
25
26
27
28
29
30
31
const upload = multer({
    storage: multer.diskStorage({
        destination(req, file, cb) {
            cb(null, 'uploads/');
        }, // 저장 경로 변경
        filename(req, file, cb) {
            cb(null, new Date().valueOf() + path.extname(file.originalname));
        }, // 파일명 변경
     }),
});

Jiwon Yoon's avatar
Jiwon Yoon committed
32
33
router.route('/regist')
    .post(productCtrl.regist)
kusang96's avatar
kusang96 committed
34
// upload.array('main_image'), 
Jiwon Yoon's avatar
Jiwon Yoon committed
35
export default router