forked from getumbrel/umbrel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken packages due to invalid gitignore
- Loading branch information
1 parent
6be02e8
commit c909e5c
Showing
4 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ data/ | |
!tor/run/.gitkeep | ||
.umbrel-dev | ||
jwt | ||
bin | ||
./bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |