-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
763 additions
and
6,650 deletions.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ENVIRONMENT=development | ||
# production | ||
RPC_URL=https://api.devnet.solana.com |
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 |
---|---|---|
|
@@ -26,3 +26,4 @@ lerna-debug.log* | |
|
||
# misc | ||
.DS_Store | ||
.env |
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
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
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,109 @@ | ||
import { serve } from '@hono/node-server'; | ||
import everstake from './everstake/route'; | ||
import { cors } from 'hono/cors'; | ||
import { swaggerUI } from '@hono/swagger-ui'; | ||
import * as path from "node:path"; | ||
import { readFileSync } from "node:fs"; | ||
import { OpenAPIHono, createRoute } from '@hono/zod-openapi'; | ||
import { z } from "zod"; | ||
var mime = require('mime-types') | ||
|
||
const app = new OpenAPIHono(); | ||
app.use('/*', cors()); | ||
|
||
// <--Actions--> | ||
app.route('/api/everstake/stake', everstake); | ||
// </--Actions--> | ||
|
||
app.doc('/doc', { | ||
info: { | ||
title: 'An API', | ||
version: 'v1', | ||
}, | ||
openapi: '3.1.0', | ||
}); | ||
|
||
app.get( | ||
'/swagger-ui', | ||
swaggerUI({ | ||
url: '/doc', | ||
}), | ||
); | ||
|
||
app.get("/actions.json", async (c) => { | ||
const [payload, mime_type] = loadFile('actions.json'); | ||
return new Response(payload, { | ||
headers: { | ||
"content-type": mime_type, | ||
}, | ||
status: 200, | ||
}); | ||
}); | ||
|
||
// Download File | ||
const downloadFileRoute = createRoute({ | ||
method: "get", | ||
path: "/static/{file}", | ||
summary: "static files", | ||
tags: ['Static'], | ||
request: { | ||
params: z.object({ | ||
file: z.string().openapi({ | ||
param: { | ||
name: 'file', | ||
in: 'path', | ||
}, | ||
type: 'string', | ||
example: 'file.jpg', | ||
}), | ||
}), | ||
}, | ||
responses: { | ||
200: { | ||
content: { | ||
"image/png": { | ||
schema: z.any().openapi({ | ||
type: "object", | ||
format: "binary", | ||
}), | ||
} | ||
}, | ||
description: | ||
"Return file, contentType can be image/png or image/jpeg", | ||
}, | ||
}, | ||
}); | ||
|
||
// disable ts check because hono openapi cannot validate raw response | ||
// @ts-ignore: Unreachable code error | ||
app.openapi(downloadFileRoute, async (c) => { | ||
const file = c.req.param('file'); | ||
const [payload, mime_type] = loadFile(file); | ||
return new Response(payload, { | ||
headers: { | ||
"content-type": mime_type, | ||
}, | ||
status: 200, | ||
}); | ||
}); | ||
|
||
function loadFile( | ||
file: string | ||
): [Buffer, string] { | ||
const payload = readFileSync(path.join("./static", file)); | ||
const mime_type = mime.lookup(path.join("./static", file)); | ||
return [payload, mime_type] | ||
} | ||
|
||
const port = 3000; | ||
console.log( | ||
`Server is running on port ${port} | ||
Visit http://localhost:${port}/swagger-ui to explore existing actions | ||
Visit https://actions.dialect.to to unfurl action into a Blink | ||
`, | ||
); | ||
|
||
serve({ | ||
fetch: app.fetch, | ||
port, | ||
}); |
0
examples/openapi.ts → actions/openapi.ts
100644 → 100755
File renamed without changes.
Oops, something went wrong.