webtides / luna-js

MIT License
8 stars 0 forks source link

feat: bundle the framework without starting luna to allow custom handers #105

Closed lukas-schardt closed 2 years ago

lukas-schardt commented 2 years ago

With this we open up the possibility for other developers to write custom handlers for their luna application. Testing wise i have updated the luna docs (https://docs.lunajs.dev/) to use this version.

The script that is needed on the custom project can look like this.

const serverless = require('serverless-http');
const { prepareLuna, callHook, HOOKS } = require('./.build/generated/framework.js');

let server = undefined;

const initialize = async () => {
    server = await prepareLuna();
    await server.prepare();

    callHook(HOOKS.SERVER_STARTED, { app: server.app });
};

const handler = async (event, context) => {
    if (!server) {
        await initialize();
    }

    return serverless(server.app, {
        binary: ['image/*', 'application/*'],
    })(event, context);
};

module.exports.handler = handler;

closes #104