-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (41 loc) · 1.85 KB
/
server.js
File metadata and controls
58 lines (41 loc) · 1.85 KB
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
// server.js
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
var categoryRoutes = require('./actions/category/routes');
var loginRoutes = require('./actions/login/routes');
var product = require('./actions/product/index');
var uploader = require('./actions/s3/index');
var categoryproduct = require('./actions/categoryproduct/index');
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
var port = process.env.PORT || 8081; // set our port
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
categoryRoutes.register(router);
loginRoutes.register(router);
new product.componentProduct(router);
new uploader.S3Uploader(router);
new categoryproduct.CategoryProduct(router);
// more routes for our API will happen here
app.all('*', function (req, res, next) {
if (!req.get('Origin')) return next();
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
res.set('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type');
if ('OPTIONS' == req.method) return res.send(200);
next();
});
// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/', router);
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('api running on port 8081');