Skip to content

Commit

Permalink
change impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Oct 26, 2023
1 parent 504d5e3 commit af1d0a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 32 additions & 1 deletion modelina-website/src/pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getCSharpModels } from '@/pages/api/functions/CSharpGenerator';
import { getCplusplusModels } from './functions/CplusplusGenerator';
import { getKotlinModels } from './functions/KotlinGenerator';
import { getPhpModels } from './functions/PhpGenerator';
import { Handler, HandlerEvent } from '@netlify/functions';

export async function generateNewCode(message: GenerateMessage): Promise<UpdateMessage | Error> {
let input: any = defaultAsyncapiDocument;
Expand Down Expand Up @@ -79,4 +80,34 @@ export default async function generate(req: NextApiRequest, res: NextApiResponse
error: e.message
});
}
}
}

/**
* Netlify function specific code, can be ignored in local development.
*/

const handler: Handler = async (event: HandlerEvent) => {
if (event.httpMethod !== 'POST') {
return { statusCode: 405, body: `Method ${event.httpMethod} Not Allowed` };
}
if (!event.body) {
return { statusCode: 405, body: 'Missing body' };
}
try {
const message = JSON.parse(event.body) as GenerateMessage;
const response = await generateNewCode(message);
return {
statusCode: 200,
body: JSON.stringify(response)
};
} catch (e) {
console.error(e);
return {
statusCode: 500,
body: JSON.stringify({
error: 'There was an error generating the models'
})
};
}
}
export { handler };
4 changes: 4 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
[build.environment]
NODE_VERSION = "18.17.0"
NPM_VERSION = "9.6.7"
NEXT_PUBLIC_API_PATH = "/.netlify/functions"

[functions]
directory = "modelina-website/.next/server/pages/api"

[[plugins]]
package = "@netlify/plugin-nextjs"

0 comments on commit af1d0a3

Please sign in to comment.