Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
luna
Commits
80a1b4d1
Commit
80a1b4d1
authored
Sep 02, 2017
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add node server for test
parent
9f9f1699
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
app.js
app.js
+82
-0
No files found.
app.js
0 → 100644
View file @
80a1b4d1
/**
* Created by liuzheng on 7/17/16.
*/
var
server
=
{};
var
http
=
require
(
'http'
);
var
express
=
require
(
'express'
);
var
io
=
require
(
'socket.io'
);
// var pty = require('pty.js');
// var terminal = require('term.js');
var
socket
;
var
term
;
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
);
// let socket.io handle sockets
io
=
io
.
listen
(
server
,
{
log
:
false
});
io
.
sockets
.
on
(
'connection'
,
function
(
s
)
{
// when connect, store the socket
socket
=
s
;
// handme incoming data (client -> server)
socket
.
on
(
'data'
,
function
(
data
)
{
term
.
write
(
data
);
});
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
});
console
.
log
(
'Please open your browser with http://127.0.0.1:8888'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment