-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (34 loc) · 1.94 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
// 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');
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 4040; // set our port
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// GET: returns all enterprises
router.get('/enterprises', function(req, res) {
console.log('GET request on /enterprises/' + req.params.decimal);
res.setHeader( "Access-Control-Allow-Origin", req.headers.origin );
res.json({"enterprises":[{"decimal":0,"organization":"reserved","contact":"Internet Assigned Numbers Authority","email":"iana&iana.org"},{"decimal":1,"organization":"NxNetworks","contact":"Michael Kellen","email":"OID.Admin&NxNetworks.com"}]});
});
// GET: returns a specific enterprise from the decimal
router.get('/enterprises/:decimal', function(req,res) {
console.log('GET request on /enterprises/' + req.params.decimal);
res.setHeader( "Access-Control-Allow-Origin", req.headers.origin );
res.json({"enterprises":[{"decimal":0,"organization":"reserved","contact":"Internet Assigned Numbers Authority","email":"iana&iana.org"},{"decimal":1,"organization":"NxNetworks","contact":"Michael Kellen","email":"OID.Admin&NxNetworks.com"}]});
});
// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Node server.app running! Magic happens on port ' + port);