-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
92 lines (78 loc) · 2.81 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
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
const express = require('express');
var bodyParser = require('body-parser')
var cors = require('cors')
var authenticate = require('./authentication');
var S3 = require('./S3_api');
var multer = require('multer');
//var upload = multer({ dest: __dirname + '/images' });
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, __dirname+'/images');
},
filename: function (req, file, cb) {
cb(null, Date.now() + '.jpg'); //Appending .jpg
}
})
var upload = multer({ storage: storage });
//sample db data for testing:
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cors({
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}));
app.options('*', cors())
// create the homepage route at '/'
app.get('/', (req, res) => {
res.sendFile(__dirname+"/index.html");
})
//login page
app.get('/login', (req,res) => {
res.sendFile(__dirname+"/"+"login.html");
// var email = req.body.email;
// var pass = req.body.password;
// //function call to fetch user details for future
// //error handling
})
//register page
app.get('/register', (req,res) => {
res.sendFile(__dirname+"/"+"register.html");
//function call to insert in DB
})
app.get('/forgotPass',(req,res) => {
res.sendFile(__dirname + "/" + "forgotpass.html");
});
app.post('/fetchByCategory', authenticate.fetchCategory);
app.post('/fetchALL', authenticate.fetchALL);
app.post('/fetchByPandC', authenticate.fetchbyPandC);
//app.get('/fetch')
//POST functions
app.post('/addToCart',authenticate.AddtoCart);
app.post('/Viewcart',authenticate.ViewCart);
app.post('/login-auth-customer', authenticate.login);
app.post('/login-auth-seller', authenticate.loginmerchant);
app.post('/register-auth-customer', authenticate.register);
app.post('/fetchByPriceRange',authenticate.fetchByPriceRange);
app.post('/fetchallcategories',authenticate.fetchAllCategories);
app.post('/getMerchant',authenticate.getMerchantbyID);
app.post('/getCategorybyId',authenticate.getCategorybyID);
app.post('/getShipper',authenticate.getShipper)
app.post('/addProduct',upload.single('image'),async function (req,res) {
console.log('in');
if(req.file){
res.json(req.file);
console.log(req.file.filename);
link = (await S3.S3_getURL(req.file.path,req.file.originalname,'dbsprojimg1')).split("?")[0];
console.log(link);
authenticate.Addproduct(link,req.body);
}
else console.log('error');
});
//app.post('/register-auth-seller'.authenticate.register);
app.post('/forgot-auth', authenticate.forgotpass);
// (async function test(){
// const localImage = './shoe.jpeg' ;
// const imageRemoteName = `shoe_${new Date().getTime()}.jpeg` ;
// var link = await S3.S3_getURL(localImage,imageRemoteName,'dbsprojimg');
// })();
app.listen(8001);