Deepkit
The following examples only work with deepkit over HTTP, you cannot use this framework to support websocket or rpc.
First, you need to ensure you have the libs installed, so run this code:
npm i --save @deepkit/app @deepkit/core @deepkit/framework @deepkit/http @deepkit/type @deepkit/type-compiler
Then, you need you just need to use the HttpDeepkitFramework when you create your adapter, like:
import { App } from '@deepkit/app';
import { FrameworkModule } from '@deepkit/framework';
import { HtmlResponse, HttpKernel, HttpModule, HttpRouterRegistry } from '@deepkit/http';
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { HttpDeepkitFramework } from '@h4ad/serverless-adapter/frameworks/deepkit';
const app = new App({
controllers: [],
module: [
new HttpModule(),
new FrameworkModule()
],
});
const router = app.get(HttpRouterRegistry);
router.get('/', () => {
return new HtmlResponse('<h1>Sample in Deepkit Project</h1>');
});
const httpKernel = app.get(HttpKernel);
export const handler = ServerlessAdapter.new(httpKernel)
.setFramework(new HttpDeepkitFramework())
// .setHandler(new DefaultHandler())
// .setResolver(new PromiseResolver())
// .addAdapter(new AlbAdapter())
// .addAdapter(new SQSAdapter())
// .addAdapter(new SNSAdapter())
// after put all methods necessary, just call the build method.
.build();
Need more examples? See more examples here.
Is your application instance creation asynchronous? Look the LazyFramework which helps you in asynchronous startup.
About AWS
I was only able to get Deepkit working when you deploy using NodeJS 16.x and using the x86_64
architecture.
Also, I tried using the serverless-offline
package and it throws an error about could not find handler
, not sure why
I changed the deployment configuration to upload code manually. So if you like to use serverless framework
, know
that you will have problems trying to test locally.
FAQ
ERR_DLOPEN_FAILED
Error message: /var/task/node_modules/turbo-net/build/Release/turbo_net.node: cannot open shared object file: No such file or directory
Solution: Change your lambda architecture to x86_64
.
ENOENT
Error message: no such file or directory, mkdir 'var/debug/' Solution:
// change these options
new HttpModule({ debug: true }),
new FrameworkModule({ debug: true, httpLog: true }),
// for
new HttpModule({ debug: false }),
new FrameworkModule({ debug: false, httpLog: false }),
Need to deal with CORS? See CorsFramework which helps you to add correct headers.