-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (93 loc) · 2.83 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const express = require('express');
const app = express();
const port = 3000;
const path = require('path');
//Enable CORS
const cors = require('cors');
app.use(cors());
//Http Request Logger
// const morgan = require('morgan');
// app.use(morgan('combined'));
// Connect to DB
const db=require('./config/db');
db.connect();
//Parsing data received from client
const bodyParser = require('body-parser');
app.use(bodyParser.json());
//import model
// const Product = require('../models/Product');
// var storage = multer.diskStorage({
// destination: "images",
// filename: (req, file, cb) => {
// cb(null, `${Date.now()}--${file.originalname}`);
// // console.log(file.originalname)
// }
// })
// maxSize = 10*1024*1024
// var upload = multer({
// storage: storage,
// limits: {
// fileSize: maxSize
// }
// }).single("file")
// app.post("/upload", (req, res)=>{
// upload(req, res, err =>{
// if(err){
// res.json({message: err.message})
// }
// else{
// //Insert Data into DB
// let productInfo = new Product({
// name: req.body.name,
// category: req.body.category,
// label: req.body.label,
// thumbPath: req.file.filename,
// weight: req.body.weight,
// color: req.body.color,
// price: req.body.price,
// description: req.body.description,
// benefit: req.body.benefit,
// instruction: req.body.instruction
// })
// productInfo.save()
// // chuwa
// res.json({message: "Success"});
// // console.log(("file receive: ", req.file.filename))
// }
// })
// })
//api get all products
// app.get("/products", async (req, res) => {
// try {
// let products = await Product.find();
// res.json(products);
// } catch (error) {
// res.json({Message: error.message})
// }
// })
//api get product info
// app.get('/products/:id', async (req, res) => {
// try {
// let productInfo = await Product.findById(req.params.id);
// res.json(productInfo);
// } catch (err) {
// res.json({message : err.message})
// }
// })
app.use(express.static(path.join(__dirname, '/images')))
//Import Product Routing
const productRouter = require('./routes/Product');
app.use('/', productRouter);
//Import User Routing
const userRouter = require('./routes/User');
app.use('/users', userRouter);
//Import Admin Routing
const adminRouter = require('./routes/Admin');
app.use('/admins', adminRouter);
//import auth routing
const authRouter = require('./routes/auth');
// const { session } = require('passport');
app.use('/auth', authRouter);
app.listen(port, () => {
console.log(`My server listening on port ${port}`);
});