Skip to content

Commit

Permalink
Merge pull request #62 from hackclub/migrate-cli-to-javascript
Browse files Browse the repository at this point in the history
migrate cli from ruby to javascript
  • Loading branch information
dispherical authored Sep 10, 2024
2 parents 27bf483 + dc901ac commit 99c778c
Show file tree
Hide file tree
Showing 34 changed files with 575 additions and 645 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
*.sqlite
2 changes: 2 additions & 0 deletions cli/.whitelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.$USERNAME.hackclub.app
$USERNAME.hackclub.app
7 changes: 0 additions & 7 deletions cli/Gemfile

This file was deleted.

14 changes: 0 additions & 14 deletions cli/Gemfile.lock

This file was deleted.

71 changes: 0 additions & 71 deletions cli/add42_subdomain.sh

This file was deleted.

106 changes: 0 additions & 106 deletions cli/add_domain.sh

This file was deleted.

71 changes: 0 additions & 71 deletions cli/add_subdomain.sh

This file was deleted.

31 changes: 31 additions & 0 deletions cli/caddy_migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
const data = JSON.parse("./caddyfile.json")

const set = [];
const routes = data.apps.http.servers.srv0.routes;

routes.forEach(route => {
const match = route.match && route.match[0];
const handle = route.handle && route.handle[0];

if (match && match.host && handle && handle.routes) {
const proxyRoute = handle.routes[0].handle[0];
if (proxyRoute.handler === 'reverse_proxy') {
const proxyDial = proxyRoute.upstreams[0].dial;
match.host.forEach(hostname => {
if (!hostname || !proxyDial) return
const match = proxyDial.match(/\/home\/([^\/]+)\//);
const username = (match && match[1]) ? match[1] : "root"

set.push({ domain: hostname, proxy: proxyDial, username: username });
});
}
}
});
async function main() {
await prisma.domain.create({
data: set
})
}
main()
Loading

0 comments on commit 99c778c

Please sign in to comment.