Skip to content

Commit

Permalink
fix(web): fix create function default code (labring#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk authored Sep 19, 2023
1 parent 8c68089 commit 0b903e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions web/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export const COLOR_MODE = {
dark: "dark",
};

export const DEFAULT_CODE = `import cloud from '@lafjs/cloud'
export default async function (ctx: FunctionContext) {
console.log('Hello World')
return { data: 'hi, laf' }
}
`;

export enum APP_SETTING_KEY {
INFO = "info",
ENV = "env",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { debounce } from "lodash";

import { MoreTemplateIcon, TextIcon } from "@/components/CommonIcon";
import InputTag from "@/components/InputTag";
import { SUPPORTED_METHODS } from "@/constants";
import { DEFAULT_CODE, SUPPORTED_METHODS } from "@/constants";

import { useCreateFunctionMutation, useUpdateFunctionMutation } from "../../../service";
import useFunctionStore from "../../../store";
Expand Down Expand Up @@ -58,7 +58,7 @@ const CreateModal = (props: {
description: functionItem?.desc || "",
websocket: !!functionItem?.websocket,
methods: functionItem?.methods || ["GET", "POST"],
code: functionItem?.source?.code || aiCode || "",
code: functionItem?.source?.code || aiCode || DEFAULT_CODE || "",
tags: functionItem?.tags || [],
};

Expand Down

0 comments on commit 0b903e8

Please sign in to comment.