Commit 7403a128 authored by i317280's avatar i317280

add HttpService

parent 761d91a2
......@@ -15,68 +15,63 @@ var buff = [];
server.run = function (options) {
// create shell process
// term = pty.fork(
// process.env.SHELL || 'sh',
// [],
// {
// name: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
// ? 'xterm-256color'
// : 'xterm',
// cols: 80,
// rows: 24,
// cwd: process.env.HOME
// }
// );
//
// // store term's output into buffer or emit through socket
// term.on('data', function (data) {
// return !socket ? buff.push(data) : socket.emit('data', data);
// });
// console.log('Created shell with pty master/slave pair (master: %d, pid: %d)', term.fd, term.pid);
var app = express();
var server = http.createServer(app);
app.use("/", express.static(__dirname + '/dist/')); // 创建服务端
app.use("/socket.io/", express.static(__dirname + '/api/')); // 创建服务端
// let term.js handle req/res
// app.use(terminal.middleware());
// let server listen on the port
options = options || {};
server.listen(options.port || 8080);
var app = express();
var server = http.createServer(app);
var apis = express.Router();
app.use("/", express.static(__dirname + '/dist/')); // 创建服务端
// app.use("/socket.io/", express.static(__dirname + '/api/')); // 创建服务端
// let term.js handle req/res
// app.use(terminal.middleware());
apis.route('/browser')
.post(function (req, res) {
console.log(req);
res.string('');
// res.json({verified: true, csrf: "liuzheng"})
});
apis.route('/checklogin')
.post(function (req, res) {
res.json({logined: true, id: 1, username: "liuzheng", name: "liuzheng"})
})
.get(function (req, res) {
res.json({logined: true})
});
// let socket.io handle sockets
io = io.listen(server, {log: false});
app.use("/api", apis);
// let server listen on the port
options = options || {};
server.listen(options.port || 3000);
io.sockets.on('connection', function (s) {
// when connect, store the socket
socket = s;
// let socket.io handle sockets
io = io.listen(server, {log: false});
// handme incoming data (client -> server)
socket.on('data', function (data) {
term.write(data);
});
io.sockets.on('connection', function (s) {
// when connect, store the socket
socket = s;
socket.on('resize', function (data) {
term.resize(data[0], data[1]);
console.log(data)
});
// handle connection lost
socket.on('disconnect', function () {
socket = null;
});
// handme incoming data (client -> server)
socket.on('data', function (data) {
term.write(data);
});
// send buffer data to client
while (buff.length) {
socket.emit('data', buff.shift());
}
socket.on('resize', function (data) {
term.resize(data[0], data[1]);
console.log(data)
});
// handle connection lost
socket.on('disconnect', function () {
socket = null;
});
// send buffer data to client
while (buff.length) {
socket.emit('data', buff.shift());
}
});
};
server.run({port: 8888});
server.run({port: 3000});
console.log('Please open your browser with http://127.0.0.1:8888');
console.log('Please open your browser with http://127.0.0.1:3000');
......@@ -3675,14 +3675,6 @@
}
}
},
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"string-width": {
"version": "1.0.2",
"bundled": true,
......@@ -3693,6 +3685,14 @@
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"stringstream": {
"version": "0.0.5",
"bundled": true,
......@@ -8674,12 +8674,6 @@
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=",
"dev": true
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
......@@ -8707,6 +8701,12 @@
}
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
......
......@@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
......
{
"/api": {
"target": "http://localhost:3000",
"secure": false
},
"/socket.io/": {
"target": "http://localhost:3000",
"secure": false
}
}
......@@ -2,14 +2,12 @@
* Created by liuzheng on 2017/8/30.
*/
import {Injectable, NgModule} from '@angular/core';
import {Http} from '@angular/http';
import {Http, Request, RequestOptionsArgs, Headers} from '@angular/http';
import {Cookie} from 'ng2-cookies/ng2-cookies';
// import {CookieService} from 'angular2-cookie/core'
import {Logger} from 'angular2-logger/core';
import 'rxjs/add/operator/map';
// import {DynamicRouteConfigurator} from './dynamicRouteConfigurator'
// import 'rxjs/add/operator/share';
// import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
declare let jQuery: any;
// declare var Terminal: any;
// declare var Clipboard: any;
......@@ -81,13 +79,84 @@ export let DataStore: {
leftbarhide: false,
windowsize: [],
};
export let CSRF: string = '';
export let Browser: {
userAgent: string;
appCodeName: string;
appName: string;
appVersion: string;
language: string;
platform: string;
product: string;
productSub: string;
vendor: string;
} = {
userAgent: navigator.userAgent,
appCodeName: navigator.appCodeName,
appName: navigator.appName,
appVersion: navigator.appVersion,
language: navigator.language,
platform: navigator.platform,
product: navigator.product,
productSub: navigator.productSub,
vendor: navigator.vendor,
};
export class HttpService {
headers = new Headers();
constructor(private _http: Http) {
}
request(url: string | Request, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.request(url, options)
}
get(url: string, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.get(url, options)
}
post(url: string, body: any, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.post(url, body, options)
}
put(url: string, body: any, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.put(url, body, options)
}
delete(url: string, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.delete(url, options)
}
patch(url: string, body: any, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.patch(url, body, options)
}
head(url: string, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.head(url, options)
}
options(url: string, options?: RequestOptionsArgs) {
options.headers = this.headers;
return this._http.options(url, options)
}
}
@Injectable()
export class AppService {
// user:User = user ;
// searchrequest: any;
constructor(private http: Http,
constructor(private _http: HttpService,
private _logger: Logger) {
if (Cookie.get('loglevel')) {
......@@ -108,17 +177,11 @@ export class AppService {
// this._logger.level = parseInt(Cookie.getCookie('loglevel'));
this._logger.level = 0;
}
const vm = this;
DataStore.socket.on('connect', function () {
console.log('DatsStore socket connected');
DataStore.socket.on('nav', function (data) {
DataStore.Nav = JSON.parse(data);
});
DataStore.socket.on('leftbar', function (data) {
if (data === 'changed') {
vm.ReloadLeftbar();
}
});
// DataStore.socket.on('popup', function (data) {
// layer.msg(data);
// });
......@@ -126,6 +189,11 @@ export class AppService {
// DataStore.socket.emit('api', 'all');
});
// this.checklogin();
this.browser()
}
browser() {
this._http.post('/api/browser', JSON.stringify(Browser)).map(res => res.json())
}
//
......@@ -243,10 +311,6 @@ export class AppService {
//
// }
//
ReloadLeftbar() {
jQuery('#left-bar').fancytree('getTree').reload();
}
// setMyinfo(user:User) {
// // Update data store
// this._dataStore.user = user;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment