-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
89 lines (74 loc) · 2.45 KB
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
require('dotenv').config();
// OAuth Middleware
const authMiddleware = require('./middlewares/auth');
// routes for the products
const product = require('./routes/product.route');
// routes for the categories
const category = require('./routes/category.route');
// routes for the providers
const provider = require('./routes/provider.route');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// OAuth2.0 middleware
app.use(authMiddleware);
// Connect to MongoDB Atlas Database
mongoose.connect('mongodb://pmsTest:pmsTest1234@cluster0-shard-00-00-z7lhh.mongodb.net:27017,cluster0-shard-00-01-z7lhh.mongodb.net:27017,cluster0-shard-00-02-z7lhh.mongodb.net:27017/pms?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority',
{ useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false })
.catch(error => console.log(error));
app.use('/products', product);
app.use('/categories', category);
app.use('/providers', provider);
const listOfEndpoints = [
'/',
'/products',
'/products/:sku',
'/products/:sku/similar',
'/categories',
'/categories/:categoryID',
'/categories/:categoryID/subCategories',
'/categories/:categoryID/products',
'/providers',
'/providers/:providerID',
'Search Query Sample: GET /products?limit=10&offset=0&qTags=gaming,mouse&attributes[colors]=white,silver',
'Search Query Sample: GET /categories?name=Peripherals',
'Search Query Sample: GET /providers?name=Razer'
]
app.get('/', (req, res) => {
res.send({ 'endpoints': listOfEndpoints })
});
app.get('*', (req, res) => {
res.status(404).send({
'status': 404,
'message': 'Invalid URL',
'endpoints': listOfEndpoints
})
});
app.post('*', (req, res) => {
res.status(404).send({
'status': 404,
'message': 'Invalid URL',
'endpoints': listOfEndpoints
})
});
app.put('*', (req, res) => {
res.status(404).send({
'status': 404,
'message': 'Invalid URL',
'endpoints': listOfEndpoints
})
});
app.delete('*', (req, res) => {
res.status(404).send({
'status': 404,
'message': 'Invalid URL',
'endpoints': listOfEndpoints
})
});
var port = 3000;
app.listen(port, () => {
console.log('Server is up and running on port: ' + port);
});