update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / framework / core / modules / routes / configuration.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 */
19
20 /**
21 * Node configuration routes module.
22 * Provides a RESTful API to provide configuration
23 * details such as api_server.
24 * @module framework/core/modules/routes/configuration
25 * @author Kiran Kashalkar <kiran.kashalkar@riftio.com>
26 */
27
28 var cors = require('cors');
29 var bodyParser = require('body-parser');
30 var configurationAPI = require('../api/configuration');
31 var Router = require('express').Router();
32 var utils = require('../../api_utils/utils');
33 var CONSTANTS = require('../../api_utils/constants.js');
34 var request = require('request');
35 var _ = require('lodash');
36
37 Router.use(bodyParser.json());
38 Router.use(cors());
39 Router.use(bodyParser.urlencoded({
40 extended: true
41 }));
42
43 Router.put('/server-configuration', cors(), function(req, res) {
44 configurationAPI.update(req).then(function(data) {
45 utils.sendSuccessResponse(data, res);
46 }, function(error) {
47 utils.sendErrorResponse(error, res);
48 });
49 });
50
51 Router.get('/server-configuration', cors(), function(req, res) {
52 configurationAPI.get(req).then(function(data) {
53 utils.sendSuccessResponse(data, res);
54 }, function(error) {
55 utils.sendErrorResponse(error, res);
56 });
57 });
58
59
60 module.exports = Router;