3a686f0942ad7a304349ec6519c6202a06543a09
[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
34 Router.use(bodyParser.json());
35 Router.use(cors());
36 Router.use(bodyParser.urlencoded({
37 extended: true
38 }));
39
40 Router.put('/server-configuration', cors(), function(req, res) {
41 configurationAPI.update(req).then(function(data) {
42 utils.sendSuccessResponse(data, res);
43 }, function(error) {
44 utils.sendErrorResponse(error, res);
45 });
46 });
47
48 Router.get('/server-configuration', cors(), function(req, res) {
49 configurationAPI.get(req).then(function(data) {
50 utils.sendSuccessResponse(data, res);
51 }, function(error) {
52 utils.sendErrorResponse(error, res);
53 });
54 });
55
56 module.exports = Router;