Skip to content

Commit

Permalink
add handle check endpoint for caddy
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Feb 20, 2024
1 parent 2a31e98 commit 918f6ea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
20 changes: 10 additions & 10 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ function main {
From your DNS provider's control panel, create the required
DNS record with the value of your server's public IP address.
+ Any DNS name that can be resolved on the public internet will work.
+ Replace example.com below with any valid domain name you control.
+ A TTL of 600 seconds (10 minutes) is recommended.
Example DNS record:
NAME TYPE VALUE
---- ---- -----
example.com A ${PUBLIC_IP:-Server public IP}
Expand Down Expand Up @@ -227,7 +227,7 @@ INSTALLER_MESSAGE
sleep 2
done
fi

apt-get update
apt-get install --yes ${REQUIRED_SYSTEM_PACKAGES}

Expand Down Expand Up @@ -295,7 +295,7 @@ DOCKERD_CONFIG
{
email ${PDS_ADMIN_EMAIL}
on_demand_tls {
ask http://localhost:3000
ask http://localhost:3000/check-handle
}
}
Expand Down Expand Up @@ -380,7 +380,7 @@ SYSTEMD_UNIT_FILE

cat <<INSTALLER_MESSAGE
========================================================================
PDS installation successful!
PDS installation successful!
------------------------------------------------------------------------
Check service status : sudo systemctl status pds
Expand All @@ -396,10 +396,10 @@ HTTP Control Panel Inbound 443 TCP Any
Required DNS entries
------------------------------------------------------------------------
Name Type Value
Name Type Value
------- --------- ---------------
${PDS_HOSTNAME} A ${PUBLIC_IP}
*.${PDS_HOSTNAME} A ${PUBLIC_IP}
${PDS_HOSTNAME} A ${PUBLIC_IP}
*.${PDS_HOSTNAME} A ${PUBLIC_IP}
Detected public IP of this server: ${PUBLIC_IP}
Expand All @@ -411,7 +411,7 @@ curl --silent \\
--user "admin:${PDS_ADMIN_PASSWORD}" \\
--header "Content-Type: application/json" \\
--data '{"useCount": 1}' \\
https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createInviteCode
https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createInviteCode
========================================================================
INSTALLER_MESSAGE
Expand Down
41 changes: 39 additions & 2 deletions service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const main = async () => {
const secrets = envToSecrets(env);
const pds = await PDS.create(cfg, secrets);
await pds.start();
httpLogger.info("pds is running");

pds.app.get("/check-handle", checkHandleRoute);
// Graceful shutdown (see also https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/)
process.on("SIGTERM", async () => {
httpLogger.info("pds is stopping");
Expand All @@ -25,4 +24,42 @@ const main = async () => {
});
};

async function checkHandleRoute(
/** @type {import('express').Request} */ req,
/** @type {import('express').Response} */ res,
/** @type {import('express').NextFunction} */ next
) {
try {
const { domain } = req.query;
if (!domain || typeof domain !== "string") {
return res.status(400).json({
error: "InvalidRequest",
message: "bad or missing domain query param",
});
}
const isHostedHandle = pds.ctx.cfg.availableUserDomains.find((avail) =>
domain.endsWith(avail)
);
if (!isHostedHandle) {
return res.status(400).json({
error: "InvalidRequest",
message: "handles are not provided on this domain",
});
}
const account = await pds.ctx.accountManager.getAccount(domain);
if (!account) {
return res.status(404).json({
error: "NotFound",
message: "handle not found for this domain",
});
}
return res.json({ did: account.did, handle: account.handle });
} catch {
return res.status(500).json({
error: "InternalServerError",
message: "Internal Server Error",
});
}
}

main();

0 comments on commit 918f6ea

Please sign in to comment.