+/* middleware */
var http = require('http');
var path = require('path');
var fs = require('fs');
var express = require('express');
var bodyParser = require('body-parser');
+var app = express();
+var server = http.createServer(app);
+var io = socketio.listen(server);
+/* app lib */
+var Config = require('./config.json');
var FileSystem = require('./server/fs/filesystem');
var Mic = require('./server/fs/mic');
var Router = require('./server/routes/router');
-var app = express();
-var server = http.createServer(app);
-var io = socketio.listen(server);
-
-app.set('port', process.env.PORT || 8081);
+/* app config */
+app.set('port', process.env.PORT || Config.TIC_WEB.PORT);
app.use(bodyParser.json());
-app.use(bodyParser.urlencoded());
-
+app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
app.use('/api', Router);
FileSystem.init();
});
-/* server - socket test
- TODO: server side logic
- - fs controllers(read/create)
- - connection with MIC
+
+
+/**
+ * Get package data from tic-core via RESTful API
+ * @URI /analysis
+ * @TYPE POST
+ */
+app.post('/analysis', function(req, res) {
+ var postData = JSON.stringify(req.body);
+ var addr = server.address();
+
+ var options = {
+ host: addr.address,
+ port: Config.TIC_CORE.PORT || addr.port + 1,
+ method: 'POST',
+ path: '/analysis',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': Buffer.byteLength(postData)
+ }
+ };
+
+ var data = '';
+ var ticCoreReq = http.request(options, function (ticCoreRes) {
+ ticCoreRes.setEncoding('utf8');
+ ticCoreRes.on('data', function (chunk) {
+ data += chunk;
+ });
+ ticCoreRes.on('end', function () {
+ res.send(data);
+ });
+ });
+
+ ticCoreReq.write(postData);
+ ticCoreReq.end();
+});
+
+
+
+/**
+ * FileSystem controller (read/create)
+ * Connection with MIC
*/
io.on('connection', function (socket) {
console.log('socket connection');
console.log('socket message');
});
-});
\ No newline at end of file
+});
) {
'use strict';
- var ANALYSIS_URL = '<%= protocol %>//<%= hostname %>:<%= port %>/analysis';
+ var ANALYSIS_URL = '<%= url %>/analysis';
var ROPO_LI = '<li class="list-group-item clearfix"><span class="tic-repository-url"><%= url %></span><button type="button" class="btn pull-right btn-default"><i class="fa fa-trash-o"></i></button></li>';
var repoStore = []; // { name, url }
function _getAnalysisUrl() {
return _.template(ANALYSIS_URL)({
- protocol: location.protocol,
- hostname: location.hostname,
- port: parseInt(location.port) + 1 // tic-core port
+ url: location.origin
});
}
};
$.ajax({
type: 'POST',
- contentType: 'text/plain',
- data: JSON.stringify(postBody),
+ contentType: 'application/json; charset=UTF-8',
dataType: 'json',
+ data: JSON.stringify(postBody),
processData: false,
- // TODO: test url
- // url: './temp/test.json',
- // url: 'http://172.21.110.103:59001/analysis',
url: _getAnalysisUrl(),
success: function(rawData) {
repoStore = rawData.data.repos;