Skip to content

Commit

Permalink
Fix broken packages due to invalid gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Mar 7, 2024
1 parent 6be02e8 commit c909e5c
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ data/
!tor/run/.gitkeep
.umbrel-dev
jwt
bin
./bin
27 changes: 27 additions & 0 deletions containers/app-auth/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node

const cookieParser = require("cookie-parser");
const express = require('express');
const { StatusCodes } = require('http-status-codes');

const authRoutes = require('../routes/auth.js');

const handleErrorMiddleware = require('../middleware/handle_error.js');
const CONSTANTS = require('../utils/const.js');

const app = express();

app.disable('x-powered-by');
app.set('view engine', 'ejs');

app.use(cookieParser(CONSTANTS.UMBREL_AUTH_SECRET));
app.use('/', authRoutes);

app.use(handleErrorMiddleware);
app.use((req, res) => {
res.status(StatusCodes.NOT_FOUND).json();
});

app.listen(CONSTANTS.PORT, () => {
console.log(`Listening on port: ${CONSTANTS.PORT}`);
});
59 changes: 59 additions & 0 deletions containers/app-proxy/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

const cookieParser = require('cookie-parser');
const express = require('express');
const waitPort = require('wait-port');

const proxy = require('../utils/proxy.js');
const umbrelRoutes = require('../routes/umbrel.js');
const handleErrorMiddleware = require('../middleware/handle_error.js');

const CONSTANTS = require('../utils/const.js');

const app = express();

app.disable('x-powered-by');
app.set('view engine', 'ejs');

app.use(cookieParser(CONSTANTS.UMBREL_AUTH_SECRET));
app.use('/umbrel_', umbrelRoutes);

app.use(handleErrorMiddleware);

const middleware = proxy.apply(app);

// We'll only open the app proxy's port
// Once the app's port is open
console.log(`Waiting for ${CONSTANTS.APP_HOST}:${CONSTANTS.APP_PORT} to open...`);

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
while(true) {
try {
await waitPort({
host: CONSTANTS.APP_HOST,
port: CONSTANTS.APP_PORT,
output: "silent",
// Wait indefinitely for the app to start
timeout: 0
});
// Exit loop on success
break;
} catch (error) {
console.log(`Error waiting for port: "${error.message}"`);
// Wait before retrying
await delay(100);
console.log('Retrying...');
}
}

console.log(`${CONSTANTS.APP.name} is now ready...`);

const server = app.listen(CONSTANTS.PROXY_PORT, () => {
console.log(`Listening on port: ${CONSTANTS.PROXY_PORT}`);
});

// This allows it to proxy WebSockets without the initial http request
server.on('upgrade', middleware.upgrade);
})();
67 changes: 67 additions & 0 deletions containers/app-proxy/test/sse-test-server/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env node

const express = require('express');

const PORT = process.env.PORT || 80;

const app = express();

app.get('/clock', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});

const clockInterval = setInterval(() => {
const data = (new Date()).toString();
res.write("data: " + data + "\n\n");
}, 1000);

req.on("close", () => {
clearInterval(clockInterval);
});
});

app.get('/', (req, res) => {
res.end(`<html>
<head>
<script>
if (!!window.EventSource) {
var source = new EventSource('/clock')
source.addEventListener('message', function(e) {
document.getElementById('data').innerHTML+= e.data + "<br>"
}, false)
source.addEventListener('open', function(e) {
document.getElementById('state').innerHTML = "Connected"
}, false)
source.addEventListener('error', function(e) {
const id_state = document.getElementById('state')
if (e.eventPhase == EventSource.CLOSED)
source.close()
if (e.target.readyState == EventSource.CLOSED) {
id_state.innerHTML = "Disconnected"
}
else if (e.target.readyState == EventSource.CONNECTING) {
id_state.innerHTML = "Connecting..."
}
}, false)
} else {
console.log("Your browser doesn't support SSE")
}
</script>
</head>
<body>
<h2>Status: <span id="state"></span></h2>
<h2>Data</h2>
<pre id="data"></pre>
</body>
</html>`);
});

app.listen(PORT, () => {
console.log(`Listening on port: ${PORT}`);
});

0 comments on commit c909e5c

Please sign in to comment.