added dockerfile

This commit is contained in:
2024-12-15 10:35:09 -05:00
parent b87d377405
commit f2573655b6
3 changed files with 41 additions and 5 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM node:latest
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN mkdir -p /app/secrets && chmod -R 700 /app/secrets
EXPOSE 5164
ENV NODE_ENV=production
CMD ["node", "."]
+11
View File
@@ -0,0 +1,11 @@
services:
app:
build:
context: .
ports:
- "5164:3000"
volumes:
- ./secrets:/app/secrets
environment:
PORT: 3000
NODE_ENV: production
+14 -5
View File
@@ -6,13 +6,12 @@ import expressWs from 'express-ws';
import { spawn } from 'node-pty';
import json from './secrets/config.json' with { type: 'json' };
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const __dirname = path.dirname(fileURLToPath(import.meta.url)),
PORT = process.env.PORT || 3000,
app = express();
const app = express();
expressWs(app); // enable websockets for the app
const PORT = 3000;
// configure session
app.use(session({
@@ -21,6 +20,7 @@ app.use(session({
saveUninitialized: false
}));
// parse form data
app.use(express.urlencoded({ extended: true }));
app.use(express.json({ extended: true }));
@@ -36,11 +36,13 @@ function requireAuth(req, res, next) {
}
}
// serve login page
app.get('/login', (req, res) => {
res.sendFile('login.html', { root: path.join(__dirname, 'HTML') });
});
// process login
app.post('/login', (req, res) => {
try {
@@ -74,11 +76,13 @@ app.post('/login', (req, res) => {
}
});
// shell interface
app.get('/shell', requireAuth, (req, res) => {
res.sendFile('shell.html', { root: path.join(__dirname, 'HTML') });
});
// logout route
app.get('/logout', (req, res) => {
req.session.destroy(() => {
@@ -86,6 +90,7 @@ app.get('/logout', (req, res) => {
});
});
// when a websocket is opened at /shell-ws, spawn a fish shell in a pty
app.ws('/shell-ws', (ws, req) => {
// spawn a fish shell using node-pty with a pseudo-terminal
@@ -110,4 +115,8 @@ app.ws('/shell-ws', (ws, req) => {
ws.on('close', () => shell.kill());
});
app.listen(PORT, () => console.log('server listening on http://localhost:' + PORT));
app.get('/', (req, res) => res.end());
app.listen(PORT, '0.0.0.0', () => console.log('server listening on http://localhost:' + PORT));