blob: 6f4c88a62d119658a4c65716dbdde16fcfe06b43 [file] [log] [blame]
Michael Lando451a3402017-02-19 10:28:42 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21var express = require('express');
22var mockApis = require('../configurations/mock.json').sdcConfig;
23//var mockUris = require('../configurations/mock.json');
24var cors = require('cors');
25var multer = require('multer')
26var basePathToMockData = './mock-data/';
27var app = express();
28
29var allowedHeaders = 'Content-Type,Authorization,If-Modified-Since,';
30allowedHeaders += mockApis.cookie.userIdSuffix;
31allowedHeaders += ','+mockApis.cookie.userEmail;
32allowedHeaders += ','+mockApis.cookie.userFirstName;
33allowedHeaders += ','+mockApis.cookie.userLastName;
34allowedHeaders += ','+mockApis.cookie.xEcompRequestId;
35
36
37
38app.use(cors({
39 // origin: '*',
40 origin: function(origin, callback) {
41 callback(null, true);
42 },
43 methods: 'GET, POST, PUT, DELETE',
44 allowedHeaders: allowedHeaders,
45 credentials: true
46}));
47
48//set cookie middleware
49app.use(function(req, res, next) {
50
51 res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || mockApis.userTypes.designer.userId );
52 res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || mockApis.userTypes.designer.email);
53 res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || mockApis.userTypes.designer.firstName);
54 res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || mockApis.userTypes.designer.lastName);
55 res.cookie(mockApis.cookie.xEcompRequestId, req.headers[mockApis.cookie.xEcompRequestId] || mockApis.userTypes.designer.lastName);
56 next();
57});
58
59var userRoutes = require('./routes/user');
60app.use('/v1/user', userRoutes);
61var resourceRoutes = require('./routes/resource');
62app.use('/v1/resource', resourceRoutes);
63var templateRoutes = require('./routes/template');
64app.use('/v1/template', templateRoutes);
65var propertyRoutes = require('./routes/property');
66app.use('/v1/resource/:resourceId/property', propertyRoutes);
67var resourcesRoutes = require('./routes/resources');
68app.use('/v1/catalog/resources', resourcesRoutes);
69
70/******************************************* MOCKS ENPOINTS *************************************************/
71/* get user details */
72// app.get(mockApis.api.GET_user, function (req, res) {
73// var user = require(basePathToMockData+'user/user.json');
74// res.send(user);
75// });
76
77/* get elements */
78app.get(mockApis.api.GET_element, function (req, res) {
79
80 var element = require(basePathToMockData+'element/element.json');
81 res.send(element);
82});
83
84/* get elements */
85app.get(mockApis.api.GET_catalog, function (req, res) {
86
87 var element = require(basePathToMockData+'element/element.json');
88 res.send(element);
89});
90
91/* get categories */
92app.get(mockApis.api.GET_category, function (req, res) {
93
94 var categories = require(basePathToMockData+'category/category.json');
95 res.send(categories);
96});
97
98
99/* get categories */
100app.get(mockApis.api.GET_configuration_ui, function (req, res) {
101
102 var categories = require(basePathToMockData+'artifact/artifact-types.json');
103 res.send(categories);
104});
105
106
107
108
109
110
111
112
113//upload artifact file
114app.use(multer({ dest: './uploads/',
115 rename: function (fieldname, filename) {
116 return filename+Date.now();
117 },
118 onFileUploadStart: function (file) {
119 console.log(file.originalname + ' is starting ...')
120 },
121 onFileUploadComplete: function (file) {
122 console.log(file.fieldname + ' uploaded to ' + file.path)
123 done=true;
124 }
125}));
126
127var done=false;
128app.post(mockApis.api.GET_resource_artifact,function(req,res){
129 if(done==true){
130 console.log(req.files);
131 res.end("File uploaded.");
132 }
133});
134
135
136/**************************************************** *******************************************************/
137
138var server = app.listen(9999, function () {
139 console.log('mock server listening on port %d', server.address().port);
140});