cp dines
This commit is contained in:
parent
f9f44b7ab5
commit
e4a152b5b3
2 changed files with 12 additions and 9 deletions
|
@ -6,6 +6,10 @@
|
||||||
// eslint-disable-next-line import/order
|
// eslint-disable-next-line import/order
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const http = require('http');
|
||||||
|
const socketIO = require('socket.io');
|
||||||
|
const appSocket = require('./socket');
|
||||||
|
const { connectTerminalWS } = require('./routes');
|
||||||
|
|
||||||
const nodeRoot = path.dirname(require.main.filename);
|
const nodeRoot = path.dirname(require.main.filename);
|
||||||
const publicPath = path.join(nodeRoot, 'client', 'public');
|
const publicPath = path.join(nodeRoot, 'client', 'public');
|
||||||
|
@ -25,8 +29,8 @@ const staticFileConfig = {
|
||||||
|
|
||||||
function startServer() {
|
function startServer() {
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = require('http').createServer(app);
|
const server = http.createServer(app);
|
||||||
const io = require('socket.io')(server, {
|
const io = socketIO(server, {
|
||||||
transports: ['websocket'],
|
transports: ['websocket'],
|
||||||
serveClient: false,
|
serveClient: false,
|
||||||
path: '/ssh/socket.io',
|
path: '/ssh/socket.io',
|
||||||
|
@ -34,23 +38,22 @@ function startServer() {
|
||||||
cors: { origin: '*' },
|
cors: { origin: '*' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const appSocket = require('./socket');
|
|
||||||
const { connectRoute: connect } = require('./routes');
|
|
||||||
|
|
||||||
app.disable('x-powered-by');
|
app.disable('x-powered-by');
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.post('/ssh/host/:host?', connect);
|
app.post('/ssh/host/:host?', connectTerminalWS);
|
||||||
// ======== To remove ========
|
// ======== To remove ========
|
||||||
// Static files..
|
// Static files..
|
||||||
app.post('/ssh', express.static(publicPath, staticFileConfig));
|
app.post('/ssh', express.static(publicPath, staticFileConfig));
|
||||||
app.use('/ssh', express.static(publicPath, staticFileConfig));
|
app.use('/ssh', express.static(publicPath, staticFileConfig));
|
||||||
// ===========================
|
// ===========================
|
||||||
app.get('/ssh/host/:host?', connect);
|
app.get('/ssh/host/:host?', connectTerminalWS);
|
||||||
|
|
||||||
io.on('connection', appSocket);
|
io.on('connection', appSocket);
|
||||||
|
|
||||||
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
startServer();
|
const server = startServer();
|
||||||
|
|
||||||
module.exports = { server, config };
|
module.exports = { server, config };
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ const nodeRoot = path.dirname(require.main.filename);
|
||||||
|
|
||||||
const publicPath = path.join(nodeRoot, 'client', 'public');
|
const publicPath = path.join(nodeRoot, 'client', 'public');
|
||||||
|
|
||||||
exports.connectRoute = function connectRoute(req, res) {
|
exports.connectTerminalWS = function (req, res) {
|
||||||
res.sendFile(path.join(path.join(publicPath, 'client.htm')));
|
res.sendFile(path.join(path.join(publicPath, 'client.htm')));
|
||||||
|
|
||||||
// let { host, port } = config.ssh;
|
// let { host, port } = config.ssh;
|
||||||
|
|
Loading…
Reference in a new issue