4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 /*Define dependencies.*/
22 var express
= require('express');
23 var multer
= require('multer');
24 var cors
= require('cors');
25 var launchpadServer
= express();
26 var apiServer
= express();
28 var path
= require('path');
30 /*Configure the multer.*/
32 //apiServer.use(function(req, res, next) {
33 // res.header('Access-Control-Allow-Origin', '*');
34 // res.header('Access-Control-Allow-Headers', '*');
41 "timestamp": 1445452293.688965,
42 "value": "onboard-started",
43 "text": "onboarding process started"
46 "timestamp": 1445452293.7836523,
47 "value": "onboard-pkg-upload",
48 "text": "uploading package"
51 "timestamp": 1445452293.8315961,
52 "value": "onboard-img-upload",
53 "text": "uploading image"
56 "timestamp": 1445452293.8316283,
57 "value": "onboard-dsc-validation",
58 "text": "descriptor validation"
61 "timestamp": 1445452294.00448,
62 "value": "onboard-success",
63 "text": "onboarding process completed"
70 "value": "onboard vnfd/ping_vnfd.xml",
71 "timestamp": 1445452294.0032463
79 "timestamp": 1445452293.688965,
80 "value": "update-started",
81 "text": "updating process started"
84 "timestamp": 1445452293.7836523,
85 "value": "update-pkg-upload",
86 "text": "uploading package"
89 "timestamp": 1445452293.8315961,
90 "value": "update-img-upload",
91 "text": "uploading image"
94 "timestamp": 1445452293.8316283,
95 "value": "update-dsc-validation",
96 "text": "descriptor validation"
99 "timestamp": 1445452294.00448,
100 "value": "update-success",
101 "text": "updating process completed"
108 "value": "update vnfd/ping_vnfd.xml",
109 "timestamp": 1445452294.0032463
114 var exportPayload
= {
117 "timestamp": 1445452293.688965,
118 "value": "update-started",
119 "text": "download process started"
122 "timestamp": 1445452293.7836523,
123 "value": "update-pkg-upload",
124 "text": "building package"
127 "timestamp": 1445452293.8315961,
128 "value": "update-img-upload",
129 "text": "building image"
132 "timestamp": 1445452293.8316283,
133 "value": "update-dsc-validation",
134 "text": "descriptor validation"
137 "timestamp": 1445452294.00448,
138 "value": "download-success",
139 "text": "download process completed"
146 "value": "download nsd/ping-pong-nsd.xml",
147 "timestamp": 1445452294.0032463
152 apiServer
.use(cors());
153 launchpadServer
.use(cors());
155 apiServer
.use(multer({
157 rename: function (fieldname
, filename
) {
158 return filename
+ '-' + Date
.now();
160 onFileUploadStart: function (file
) {
161 console
.log(file
.originalname
+ ' is starting ...')
163 onFileUploadComplete: function (file
) {
164 console
.log(file
.fieldname
+ ' uploaded to ' + file
.path
)
171 launchpadServer
.get('/launchpad/catalog', function (req
, res
) {
172 res
.sendFile(path
.join(__dirname
, '../../src/assets/ping-pong-catalog.json'));
175 launchpadServer
.delete('/launchpad/catalog/nsd/:id', function (req
, res
) {
179 launchpadServer
.put('/launchpad/catalog/nsd/:id', function (req
, res
) {
183 apiServer
.post('/api/upload', function (req
, res
) {
185 res
.end('{"transaction_id": "' + Date
.now() + '"}');
189 apiServer
.get('/api/upload/:transaction_id/state', function (req
, res
) {
191 console
.log('transaction id state request', req
.params
.transaction_id
);
192 res
.end(JSON
.stringify(uploadPayload
));
196 apiServer
.post('/api/update', function (req
, res
) {
198 res
.end('{"transaction_id": "' + Date
.now() + '"}');
202 apiServer
.get('/api/update/:transaction_id/state', function (req
, res
) {
204 console
.log('transaction id state request', req
.params
.transaction_id
);
205 res
.end(JSON
.stringify(updatePayload
));
209 apiServer
.get('/api/export', function (req
, res
) {
210 res
.end('{"transaction_id": "' + Date
.now() + '"}');
213 apiServer
.get('/api/export/:transaction_id/state', function (req
, res
) {
214 console
.log('transaction id state request', req
.params
.transaction_id
);
215 res
.end(JSON
.stringify(exportPayload
));
219 launchpadServer
.listen(3000, function () {
220 console
.log('LaunchPad Server listening on port 3000');
223 apiServer
.listen(4567, function () {
224 console
.log('API Server listening on port 4567');