-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (37 loc) · 1.54 KB
/
server.js
File metadata and controls
44 lines (37 loc) · 1.54 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
var express = require('express'); // webserver serving prototype apps
var dotenv = require('dotenv'); // package loading .env configuration files
var request = require('request'); // initial request to get access_token
var morgan = require('morgan'); // get/posts requests logger/tracker
// existing sandboxes so far
var sandboxes = [
{name: "Production", url: "https://apx.cisco.com/spvss/infinitehome/infinitetoolkit/v_sandbox_1/"},
{name: "Dev", url: "https://apx.cisco.com/spvss/infinitehome/infinitetoolkit/v_sandbox_1/"},
{name: "IBC", url: "https://apx.cisco.com/spvss/infinitehome/infinitetoolkit/v2_ibc_2016/"}
];
var access_token;
var token_type;
var expires_in;
// loading .env variables
dotenv.load();
// performing initial SSO, retreaving access_token, token type & expires_in parameters
request.post({
url: 'https://cloudsso.cisco.com/as/token.oauth2',
form: {
'client_id': process.env.DEFAULT_CLIENT_ID,
'client_secret': process.env.DEFAULT_CLIENT_SECRET,
'grant_type': "client_credentials"
},
body: "test"
}, function(error, response, body) {
if (!error && response.statusCode == 200) { // TODO will need to manage errors...
body= JSON.parse(body);
access_token=body.access_token;
token_type=body.token_type;
expires_in= body.expires_in;
}
});
// starting up webserver hosting the client SPA(s)
var app = express();
app.use(express.static('public'));
app.use(morgan('dev')); //logging post/get requests to the express server
var server = app.listen(3000);