Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat(head): allow HEAD requests on endpoint
Browse files Browse the repository at this point in the history
The headers include relevant resolved tx id data without the fully resolved record data. It is a cheap way get the resolved tx id and ttl.
  • Loading branch information
dtfiedler committed Jun 18, 2024
1 parent 512aa3e commit 7886951
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ paths:
schema:
'$ref': '#/components/schemas/Info'
'/ar-io/resolver/records/{name}':
head:
parameters:
- name: name
in: path
required: true
schema:
type: string
description: |-
The name of the record to resolve
responses:
'200':
description: |-
200 response
'404':
description: |-
404 response
'500':
description: |-
500 response
get:
responses:
'200':
Expand Down
30 changes: 29 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const app = express();
app.use(
cors({
origin: '*',
methods: ['GET'],
methods: ['GET', 'HEAD'],
}),
);

Expand Down Expand Up @@ -85,6 +85,34 @@ app.get('/ar-io/resolver/info', (_req, res) => {
});
});

app.head('/ar-io/resolver/records/:name', async (req, res) => {
try {
log.debug('Checking cache for record', { name: req.params.name });
const resolvedRecordData = await cache.get(req.params.name);
if (!resolvedRecordData) {
res.status(404).send();
return;
}
const recordData = JSON.parse(resolvedRecordData.toString());
res
.status(200)
.set({
'Cache-Control': `public, max-age=${recordData.ttlSeconds}`,
'Content-Type': 'application/json',
'X-ArNS-Resolved-Id': recordData.txId,
'X-ArNS-Ttl-Seconds': recordData.ttlSeconds,
})
.send();
} catch (err: any) {
log.error('Failed to check for record', {
name: req.params.name,
message: err?.message,
stack: err?.stack,
});
res.status(500).send();
}
});

app.get('/ar-io/resolver/records/:name', async (req, res) => {
try {
// TODO: use barrier synchronization to prevent multiple requests for the same record
Expand Down

0 comments on commit 7886951

Please sign in to comment.