Giter Site home page Giter Site logo

h4ad / serverless-adapter-examples Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 3.24 MB

Working examples to show how to integrate with https://github.com/H4ad/serverless-adapter

Home Page: https://viniciusl.com.br/serverless-adapter

License: MIT License

deepkit express trpc aws aws-lambda azure azure-functions fastify firebase huawei

serverless-adapter-examples's Introduction

Serverless Adapter Examples

In the repository, you will find examples of how to deploy and integrate with frameworks and cloud supported by serverless-adapter.

Serverless adapter supports more frameworks, but I'm still working on creating examples, this thing takes a lot of time. If you want to know how to integrate with a specific framework that I haven't given an example of yet, please create a issue and I can help you.

Framework Cloud Source Documentation
Apollo Server AWS examples/apollo-server-aws Apollo Server and AWS
Apollo Server Azure examples/apollo-server-azure Apollo Server and Azure
Apollo Server Digital Ocean examples/apollo-server-digital-ocean Apollo Server and Digital Ocean
Apollo Server Firebase examples/apollo-server-firebase Apollo Server and Firebase
Apollo Server GCP examples/apollo-server-gcp Apollo Server and GCP
Deepkit AWS examples/deepkit-aws Deepkit and AWS
Deepkit Azure examples/deepkit-azure Deepkit and Azure
Deepkit Huawei examples/deepkit-huawei Deepkit and Huawei
Deepkit Firebase examples/deepkit-firebase Deepkit and Firebase
Fastify AWS Lambda Response Streaming examples/fastify-aws-stream Fastify and AWS Lambda Response Streaming
tRPC AWS examples/trpc-aws tRPC and AWS
tRPC Digital Ocean examples/trpc-digital-ocean tRPC and Digital Ocean
tRPC GCP examples/trpc-gcp tRPC and GCP
NestJS AWS examples/nestjs-aws NestJS and AWS
NestJS AWS Lambda Response Streaming examples/nestjs-aws-stream NestJS and AWS Lambda Response Streaming
NestJS Digital Ocean examples/nestjs-digital-ocean NestJS and Digital Ocean
NestJS GCP examples/nestjs-gcp NestJS and GCP

serverless-adapter-examples's People

Contributors

h4ad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

1mateus

serverless-adapter-examples's Issues

Unable to run on digitalocean function

Hi @H4ad ,
I was trying https://github.com/H4ad/serverless-adapter-examples/tree/master/examples/trpc-digital-ocean to deploy to digital ocean functions I added npm package instead of file link in package.json "@h4ad/node-modules-packer": "^1.1.0",
I was able to deploy correctly but when I click run on DO functions I am getting error

2022-09-11T13:27:48.168357007Z stdout: Error: Cannot find module '@h4ad/serverless-adapter'
2022-09-11T13:27:48.168412462Z stdout: Require stack:
2022-09-11T13:27:48.168415989Z stdout: - /tmp/ZWzb5Bqh/dist/index.js
2022-09-11T13:27:48.168418343Z stdout:     at Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
2022-09-11T13:27:48.168422641Z stdout:     at Module._load (node:internal/modules/cjs/loader:804:27)
2022-09-11T13:27:48.168425056Z stdout:     at Module.require (node:internal/modules/cjs/loader:1022:19)
2022-09-11T13:27:48.16842743Z  stdout:     at require (node:internal/modules/cjs/helpers:102:18)
2022-09-11T13:27:48.168429805Z stdout:     at Object.<anonymous> (/tmp/ZWzb5Bqh/dist/index.js:4:30)
2022-09-11T13:27:48.168433032Z stdout:     at Module._compile (node:internal/modules/cjs/loader:1120:14)
2022-09-11T13:27:48.168435366Z stdout:     at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
2022-09-11T13:27:48.16843776Z  stdout:     at Module.load (node:internal/modules/cjs/loader:998:32)
2022-09-11T13:27:48.168440095Z stdout:     at Module._load (node:internal/modules/cjs/loader:839:12)
2022-09-11T13:27:48.168442389Z stdout:     at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29) {
2022-09-11T13:27:48.168444864Z stdout:   code: 'MODULE_NOT_FOUND',
2022-09-11T13:27:48.168447138Z stdout:   requireStack: [ '/tmp/ZWzb5Bqh/dist/index.js' ]
2022-09-11T13:27:48.168449402Z stdout: }
2022-09-11T13:27:48.171598Z    stderr: The action did not initialize or run as expecte

When using the Azure Handler and TRPC Adapter, I get this bizzare error: UnhandledPromiseRejectionWarning: TypeError: context.done is not a function

/** index.ts **/
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { AzureHandler } from '@h4ad/serverless-adapter/lib/handlers/azure';
import { PromiseResolver } from '@h4ad/serverless-adapter/lib/resolvers/promise';
import { HttpTriggerV4Adapter } from '@h4ad/serverless-adapter/lib/adapters/azure';
import app, { frameworkOptions, TrpcContext } from '../router/app';
import { TrpcFramework } from '@h4ad/serverless-adapter/lib/frameworks/trpc';

export default ServerlessAdapter.new(app)
	.setHandler(new AzureHandler())
	.setResolver(new PromiseResolver())
	.setFramework(new TrpcFramework<TrpcContext>(frameworkOptions))
	.addAdapter(new HttpTriggerV4Adapter({ stripBasePath: '/api' }))
	.build();
/** app.ts **/
import * as trpc from '@trpc/server';
import {
	BufferToJSObjectTransformer,
	TrpcAdapterContext,
	TrpcFrameworkOptions,
} from '@h4ad/serverless-adapter/lib/frameworks/trpc';

export type CustomContext = { done: () => void };
export type TrpcContext = TrpcAdapterContext<CustomContext>;

interface User {
	id: string;
	name: string;
}
const userList: User[] = [
	{
		id: '1',
		name: 'KATT',
	},
];

const appRouter = trpc
	.router<TrpcContext>()
	.transformer(new BufferToJSObjectTransformer())
	.query('getUserById', {
		input: (val: unknown) => {
			if (typeof val === 'string') {
				return val;
			}
			throw new Error(`Invalid input: ${typeof val}`);
		},
		async resolve(req) {
			return userList.find((user) => (user.id = req.input));
		},
	});
export type AppRouter = typeof appRouter;

export const frameworkOptions: TrpcFrameworkOptions<TrpcContext> = {
	createContext: () => ({
		done: () => {
			console.log(this);
		},
	}),
};

export default appRouter;

Error:

[2022-12-06T21:06:39.616Z] (node:315642) UnhandledPromiseRejectionWarning: TypeError: context.done is not a function
[2022-12-06T21:06:39.616Z]     at /home/itai/.config/yarn/global/node_modules/azure-functions-core-tools/bin/workers/node/worker-bundle.js:18698:29
[2022-12-06T21:06:39.616Z]     at processTicksAndRejections (internal/process/task_queues.js:95:5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.