omnitool_on_hf / myNodeServer.js
manu-sapiens's picture
ngix 4444 edition
0526d9d
raw
history blame
1.16 kB
const fastify = require('fastify')({ logger: true });
let MANAGEMENT_SERVER_PORT = 1689;
let SERVER_HOST = '0.0.0.0';
console.log(`************ Management Server v 0.002 ************`);
fastify.get('/', async (request, reply) => {
const localUrl = request.headers['host'];
let htmlContent = `
<html>
<head><title>Proxy Server</title></head>
<body>
<button onclick="redirect()">Goto: ${localUrl}</button>
<script>
function redirect() {
window.location.replace('http://${localUrl}/omnitool');
}
</script>
<div id="logs" style="white-space: pre-wrap;"></div>
</body>
</html>
`;
reply.type('text/html').send(htmlContent);
});
const start = async () => {
try {
await fastify.listen({ port: MANAGEMENT_SERVER_PORT, host: SERVER_HOST });
console.log(`Server is listening on port ${MANAGEMENT_SERVER_PORT}`);
} catch (err) {
console.error(`Error starting server: ${err}`);
process.exit(1);
}
};
start();