-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DigitalOcean functions example #458
Comments
Hi @Soviut Sounds good. It would be good to place it under |
@yusukebe I was actually thinking it might be good under this Getting Started section since it already covers a lot of different serverless hosts (Deno, Netlify, Vercel, etc.) |
Ah, you're right. It would also be good. By the way, I want to see the actual code for the example to handle DigitalOcean requests and responses. |
export function main(args: {}): {} {
const name: string = args['name'] || 'stranger'
const greeting = 'Hello ' + name + '!'
return { body: greeting }
} They have several examples of the functions... Here is Typescript https://github.com/digitalocean/sample-functions-typescript-helloworld/blob/master/packages/sample/hello/src/hello.ts And here is an example of them wrapping Apollo Server https://github.com/digitalocean/sample-functions-apollo-graphql/blob/main/packages/default/graphql/index.ts#L44 In all cases a packages:
- name: sample
actions:
- name: hello
runtime: 'nodejs:default' All of those examples above have a project.yml in their repos. |
Also here are the DigitalOcean docs about Node serverless functions and the args that are sent. https://docs.digitalocean.com/products/functions/reference/runtimes/node-js/ export function main(event, context) {
const name = event.name || 'stranger'
const version = context.functionVersion
return {
body: `Hello ${name}! This is version ${version}.`
}
} With the {
"http": {
"headers": {
"accept": "*/*",
"accept-encoding": "gzip",
"user-agent": "curl/7.85.0",
"x-forwarded-for": "203.0.113.11",
"x-forwarded-proto": "https",
"x-request-id": "5df6f6b0d00b58217439c8376fcae23a"
},
"method": "POST",
"path": ""
},
"shark": "hammerhead"
} And the context looking like {
"activationId": "5f56b7e9fbd84b2f96b7e9fbd83b2f2e",
"apiHost": "https://faas-nyc1-2ef2e6cc.doserverless.co",
"apiKey": "",
"deadline": 1675959023728,
"functionName": "/fn-52ad03a2-8660-4f7c-55a5-81aa8bbe73b1/example",
"functionVersion": "0.0.10",
"namespace": "fn-52ad03a2-8660-4f7c-55a5-81aa8bbe73b1",
"requestId": "452164dfeced0a7ad91ee675609024e7"
} |
Thanks! I saw the code for DegitalOcean; it's interesting. But I wonder if we would need to use Hono for that. |
@yusukebe I already have an API I built with Hono for CloudFlare that I want to move to DIgitalOcean serverless functions on their "App Platform". Hono is ideal for these "wide" functions (as Supabase likes to call them) where a single function handles all my API requests. |
@yusukebe I managed to get an example working with Hono in a DigitalOcean function. import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Node.js!'))
export const main = async (event) => {
const res = await app.request(event.http.path, { method: event.http.method })
const body = await res.text()
return {
statusCode: res.status,
body,
}
} Obviously this will need more work. Things like passing environment variables from DO to Hono, etc. |
Ah, I see! That implementation is simple and good. Thank you for sharing it. |
@yusukebe yes, it's straightforward but there should definitely be an official adapter since I'm missing things like headers and such. |
It would be great if there was a DigitalOcean functions example.
Their functions seem very simple, with the request being handled by a
main(args)
entrypoint.I'm trying to figure out how to call Hono's
app.fire()
orapp.fetch()
from this entrypoint but so far no luck.The text was updated successfully, but these errors were encountered: