Skip to content

Commit

Permalink
update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Oct 26, 2023
1 parent 69dd4e4 commit c9e65bc
Show file tree
Hide file tree
Showing 8 changed files with 2,665 additions and 5,672 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ lib
output
# Where the runtime testing for Java places node modules
java_runtime_node
*.log
*.log
# Local Netlify folder
.netlify
33 changes: 33 additions & 0 deletions modelina-website/netlify/functions/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { generateNewCode } from "../../src/pages/api/generate";
import { GenerateMessage } from "../../src/types";
import { Handler, HandlerEvent } from "@netlify/functions";

/**
* 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 as default };
5,953 changes: 359 additions & 5,594 deletions modelina-website/package-lock.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions modelina-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@
"copy:docs:img": "cp -r ../docs/img public/img/docs"
},
"dependencies": {
"@monaco-editor/react": "^4.4.6",
"@netlify/functions": "^1.4.0",
"@next/font": "13.1.5",
"@monaco-editor/react": "^4.6.0",
"@netlify/functions": "2.3.0",
"@tailwindcss/aspect-ratio": "^0.4.0",
"@tailwindcss/forms": "^0.5.2",
"@tailwindcss/line-clamp": "^0.4.0",
"@tailwindcss/typography": "^0.5.9",
"cssnano": "^5.1.14",
"eslint": "8.32.0",
"eslint-config-next": "13.1.5",
"js-base64": "^3.7.4",
"lodash": "^4.17.21",
"lowlight": "^1.12.1",
"markdown-toc": "^1.2.0",
"next": "^13.5.6",
"path": "^0.12.7",
"next": "13.5.5",
"postcss": "^8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -51,6 +46,8 @@
"@types/react-syntax-highlighter": "^15.5.6",
"autoprefixer": "^10.4.13",
"cross-env": "^7.0.3",
"eslint": "8.32.0",
"eslint-config-next": "13.1.5",
"typescript": "4.9.4"
}
}
38 changes: 5 additions & 33 deletions modelina-website/src/pages/api/generate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { HandlerEvent } from '@netlify/functions';
import {
defaultAsyncapiDocument,
GenerateMessage,
Expand Down Expand Up @@ -61,7 +60,10 @@ export async function generateNewCode(message: GenerateMessage): Promise<UpdateM
}
}

async function generate(req: NextApiRequest, res: NextApiResponse) {
/**
* Next specific API function, why export default is necessary. Called when running locally.
*/
export default async function generate(req: NextApiRequest, res: NextApiResponse) {
try {
const message: GenerateMessage = JSON.parse(req.body);
const response = await generateNewCode(message);
Expand All @@ -77,34 +79,4 @@ async function generate(req: NextApiRequest, res: NextApiResponse) {
error: e.message
});
}
}

export default generate;

/**
* Netlify function specifi code, can be ignored in local development
*/
export async function handler(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'
})
};
}
}
}
2 changes: 1 addition & 1 deletion modelina-website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/helpers/docsUtils.js"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/helpers/docsUtils.js", "src/netlify/functions/generate.ts"],
"exclude": ["node_modules"]
}
8 changes: 2 additions & 6 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
publish = "modelina-website/.next"

[build.environment]
NODE_VERSION = "16.13.2"
NPM_VERSION = "8.1.2"
NEXT_PUBLIC_API_PATH = "/.netlify/functions"

[functions]
directory = "modelina-website/.next/server/pages/api"
NODE_VERSION = "18.17.0"
NPM_VERSION = "9.6.7"
Loading

0 comments on commit c9e65bc

Please sign in to comment.