create-cloudflare 0.0.0-e6ddf8a7 → 0.0.0-e7ccc859
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +74109 -57652
- package/package.json +13 -6
- package/templates/angular/c3.ts +99 -0
- package/{dist → templates}/angular/templates/tools/alter-polyfills.mjs +2 -2
- package/{dist → templates}/angular/templates/tools/copy-files.mjs +1 -1
- package/templates/astro/c3.ts +50 -0
- package/templates/common/c3.ts +14 -0
- package/templates/common/ts/package.json +0 -1
- package/templates/docusaurus/c3.ts +27 -0
- package/templates/gatsby/c3.ts +46 -0
- package/templates/hello-world/c3.ts +14 -0
- package/templates/hello-world/ts/package.json +0 -1
- package/templates/hello-world-durable-object/c3.ts +14 -0
- package/templates/hello-world-durable-object/js/.editorconfig +13 -0
- package/templates/hello-world-durable-object/js/.prettierrc +6 -0
- package/templates/{chatgptPlugin/ts → hello-world-durable-object/js}/__dot__gitignore +1 -0
- package/templates/hello-world-durable-object/js/package.json +13 -0
- package/templates/hello-world-durable-object/js/src/index.js +65 -0
- package/templates/hello-world-durable-object/js/wrangler.toml +51 -0
- package/templates/hello-world-durable-object/ts/.editorconfig +13 -0
- package/templates/hello-world-durable-object/ts/.prettierrc +6 -0
- package/templates/hello-world-durable-object/ts/__dot__gitignore +172 -0
- package/templates/hello-world-durable-object/ts/package.json +15 -0
- package/templates/hello-world-durable-object/ts/src/index.ts +78 -0
- package/templates/hello-world-durable-object/ts/tsconfig.json +101 -0
- package/templates/hello-world-durable-object/ts/wrangler.toml +51 -0
- package/templates/hono/c3.ts +25 -0
- package/templates/next/c3.ts +213 -0
- package/templates/next/templates.ts +281 -0
- package/templates/nuxt/c3.ts +59 -0
- package/templates/openapi/c3.ts +9 -0
- package/templates/openapi/ts/package.json +0 -1
- package/templates/openapi/ts/src/endpoints/taskList.ts +1 -1
- package/templates/openapi/ts/src/index.ts +2 -2
- package/templates/pre-existing/c3.ts +83 -0
- package/templates/pre-existing/js/.editorconfig +13 -0
- package/templates/pre-existing/js/.prettierrc +6 -0
- package/templates/pre-existing/js/__dot__gitignore +172 -0
- package/templates/pre-existing/js/package.json +13 -0
- package/templates/pre-existing/js/wrangler.toml +3 -0
- package/templates/queues/c3.ts +24 -0
- package/templates/queues/ts/package.json +0 -1
- package/templates/qwik/c3.ts +92 -0
- package/templates/react/c3.ts +29 -0
- package/templates/remix/c3.ts +33 -0
- package/templates/scheduled/c3.ts +14 -0
- package/templates/scheduled/ts/package.json +0 -1
- package/templates/solid/c3.ts +37 -0
- package/templates/solid/js/vite.config.js +12 -0
- package/templates/solid/ts/vite.config.ts +12 -0
- package/templates/svelte/c3.ts +77 -0
- package/templates/svelte/templates.ts +13 -0
- package/templates/vue/c3.ts +27 -0
- package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
- package/templates/chatgptPlugin/ts/README.md +0 -25
- package/templates/chatgptPlugin/ts/package.json +0 -17
- package/templates/chatgptPlugin/ts/src/index.ts +0 -33
- package/templates/chatgptPlugin/ts/src/search.ts +0 -59
- package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
- /package/{dist → templates}/angular/templates/server.ts +0 -0
- /package/{dist → templates}/angular/templates/src/_routes.json +0 -0
- /package/{dist → templates}/angular/templates/tools/paths.mjs +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
configVersion: 1,
|
|
3
|
+
id: "queues",
|
|
4
|
+
displayName: "Queue consumer & producer Worker",
|
|
5
|
+
platform: "workers",
|
|
6
|
+
copyFiles: {
|
|
7
|
+
js: {
|
|
8
|
+
path: "./js",
|
|
9
|
+
},
|
|
10
|
+
ts: {
|
|
11
|
+
path: "./ts",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
bindings: {
|
|
15
|
+
queues: [
|
|
16
|
+
{
|
|
17
|
+
boundVariable: "MY_QUEUE",
|
|
18
|
+
defaultValue: "my-queue",
|
|
19
|
+
producer: true,
|
|
20
|
+
consumer: true,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { endSection } from "@cloudflare/cli";
|
|
2
|
+
import { brandColor } from "@cloudflare/cli/colors";
|
|
3
|
+
import { spinner } from "@cloudflare/cli/interactive";
|
|
4
|
+
import { parseTs, transformFile } from "helpers/codemod";
|
|
5
|
+
import { runCommand, runFrameworkGenerator } from "helpers/command";
|
|
6
|
+
import { usesTypescript } from "helpers/files";
|
|
7
|
+
import { detectPackageManager } from "helpers/packages";
|
|
8
|
+
import { quoteShellArgs } from "../../src/common";
|
|
9
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
10
|
+
import type * as recast from "recast";
|
|
11
|
+
import type { C3Context } from "types";
|
|
12
|
+
|
|
13
|
+
const { npm, npx } = detectPackageManager();
|
|
14
|
+
|
|
15
|
+
const generate = async (ctx: C3Context) => {
|
|
16
|
+
await runFrameworkGenerator(ctx, ["basic", ctx.project.name]);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const configure = async (ctx: C3Context) => {
|
|
20
|
+
// Add the pages integration
|
|
21
|
+
const cmd = [npx, "qwik", "add", "cloudflare-pages"];
|
|
22
|
+
endSection(`Running ${quoteShellArgs(cmd)}`);
|
|
23
|
+
await runCommand(cmd);
|
|
24
|
+
|
|
25
|
+
addBindingsProxy(ctx);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const addBindingsProxy = (ctx: C3Context) => {
|
|
29
|
+
// Qwik only has a typescript template atm.
|
|
30
|
+
// This check is an extra precaution
|
|
31
|
+
if (!usesTypescript(ctx)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const s = spinner();
|
|
36
|
+
s.start("Updating `vite.config.ts`");
|
|
37
|
+
|
|
38
|
+
// Insert the env declaration after the last import (but before the rest of the body)
|
|
39
|
+
const envDeclaration = `
|
|
40
|
+
let env = {};
|
|
41
|
+
|
|
42
|
+
if(process.env.NODE_ENV === 'development') {
|
|
43
|
+
const { getBindingsProxy } = await import('wrangler');
|
|
44
|
+
const { bindings } = await getBindingsProxy();
|
|
45
|
+
env = bindings;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
transformFile("vite.config.ts", {
|
|
50
|
+
visitProgram: function (n) {
|
|
51
|
+
const lastImportIndex = n.node.body.findLastIndex(
|
|
52
|
+
(t) => t.type === "ImportDeclaration"
|
|
53
|
+
);
|
|
54
|
+
n.get("body").insertAt(lastImportIndex + 1, envDeclaration);
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Populate the `qwikCity` plugin with the platform object containing the `env` defined above.
|
|
61
|
+
const platformObject = parseTs(`{ platform: { env } }`);
|
|
62
|
+
|
|
63
|
+
transformFile("vite.config.ts", {
|
|
64
|
+
visitCallExpression: function (n) {
|
|
65
|
+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
66
|
+
if (callee.name === "qwikCity") {
|
|
67
|
+
n.node.arguments = [platformObject];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.traverse(n);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
s.stop(`${brandColor("updated")} \`vite.config.ts\``);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const config: TemplateConfig = {
|
|
78
|
+
configVersion: 1,
|
|
79
|
+
id: "qwik",
|
|
80
|
+
displayName: "Qwik",
|
|
81
|
+
platform: "pages",
|
|
82
|
+
devScript: "dev",
|
|
83
|
+
deployScript: "deploy",
|
|
84
|
+
generate,
|
|
85
|
+
configure,
|
|
86
|
+
transformPackageJson: async () => ({
|
|
87
|
+
scripts: {
|
|
88
|
+
deploy: `${npm} run build && wrangler pages deploy ./dist`,
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
export default config;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import { compatDateFlag } from "helpers/files";
|
|
4
|
+
import { detectPackageManager } from "helpers/packages";
|
|
5
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
6
|
+
import type { C3Context } from "types";
|
|
7
|
+
|
|
8
|
+
const { npm } = detectPackageManager();
|
|
9
|
+
|
|
10
|
+
const generate = async (ctx: C3Context) => {
|
|
11
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
12
|
+
|
|
13
|
+
logRaw("");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const config: TemplateConfig = {
|
|
17
|
+
configVersion: 1,
|
|
18
|
+
id: "react",
|
|
19
|
+
displayName: "React",
|
|
20
|
+
platform: "pages",
|
|
21
|
+
generate,
|
|
22
|
+
transformPackageJson: async () => ({
|
|
23
|
+
scripts: {
|
|
24
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --port 3000 -- ${npm} start`,
|
|
25
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./build`,
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
export default config;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command.js";
|
|
3
|
+
import { detectPackageManager } from "helpers/packages";
|
|
4
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
5
|
+
import type { C3Context } from "types";
|
|
6
|
+
|
|
7
|
+
const { npm } = detectPackageManager();
|
|
8
|
+
|
|
9
|
+
const generate = async (ctx: C3Context) => {
|
|
10
|
+
await runFrameworkGenerator(ctx, [
|
|
11
|
+
ctx.project.name,
|
|
12
|
+
"--template",
|
|
13
|
+
"https://github.com/remix-run/remix/tree/main/templates/cloudflare-pages",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
logRaw(""); // newline
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const config: TemplateConfig = {
|
|
20
|
+
configVersion: 1,
|
|
21
|
+
id: "remix",
|
|
22
|
+
displayName: "Remix",
|
|
23
|
+
platform: "pages",
|
|
24
|
+
generate,
|
|
25
|
+
transformPackageJson: async () => ({
|
|
26
|
+
scripts: {
|
|
27
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./public`,
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
devScript: "dev",
|
|
31
|
+
testFlags: ["--typescript", "--no-install", "--no-git-init"],
|
|
32
|
+
};
|
|
33
|
+
export default config;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import { compatDateFlag } from "helpers/files";
|
|
4
|
+
import { detectPackageManager } from "helpers/packages";
|
|
5
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
6
|
+
import type { C3Context } from "types";
|
|
7
|
+
|
|
8
|
+
const { npm } = detectPackageManager();
|
|
9
|
+
|
|
10
|
+
const generate = async (ctx: C3Context) => {
|
|
11
|
+
// Run the create-solid command
|
|
12
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
13
|
+
|
|
14
|
+
logRaw("");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const config: TemplateConfig = {
|
|
18
|
+
configVersion: 1,
|
|
19
|
+
id: "solid",
|
|
20
|
+
displayName: "Solid",
|
|
21
|
+
platform: "pages",
|
|
22
|
+
copyFiles: {
|
|
23
|
+
js: { path: "./js" },
|
|
24
|
+
ts: { path: "./ts" },
|
|
25
|
+
},
|
|
26
|
+
generate,
|
|
27
|
+
transformPackageJson: async () => ({
|
|
28
|
+
scripts: {
|
|
29
|
+
"pages:preview": `${npm} run build && npx wrangler pages dev dist ${await compatDateFlag()} --compatibility-flag nodejs_compat`,
|
|
30
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
devScript: "dev",
|
|
34
|
+
previewScript: "pages:preview",
|
|
35
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
36
|
+
};
|
|
37
|
+
export default config;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { parseTs, transformFile } from "helpers/codemod";
|
|
4
|
+
import { installPackages, runFrameworkGenerator } from "helpers/command";
|
|
5
|
+
import { compatDateFlag, usesTypescript } from "helpers/files";
|
|
6
|
+
import { detectPackageManager } from "helpers/packages";
|
|
7
|
+
import { platformInterface } from "./templates";
|
|
8
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
|
+
import type * as recast from "recast";
|
|
10
|
+
import type { C3Context } from "types";
|
|
11
|
+
|
|
12
|
+
const { npm } = detectPackageManager();
|
|
13
|
+
|
|
14
|
+
const generate = async (ctx: C3Context) => {
|
|
15
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
16
|
+
|
|
17
|
+
logRaw("");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const configure = async (ctx: C3Context) => {
|
|
21
|
+
// Install the adapter
|
|
22
|
+
const pkg = `@sveltejs/adapter-cloudflare`;
|
|
23
|
+
await installPackages([pkg], {
|
|
24
|
+
dev: true,
|
|
25
|
+
startText: "Adding the Cloudflare Pages adapter",
|
|
26
|
+
doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Change the import statement in svelte.config.js
|
|
30
|
+
transformFile("svelte.config.js", {
|
|
31
|
+
visitImportDeclaration: function (n) {
|
|
32
|
+
// importSource is the `x` in `import y from "x"`
|
|
33
|
+
const importSource = n.value.source;
|
|
34
|
+
if (importSource.value === "@sveltejs/adapter-auto") {
|
|
35
|
+
importSource.value = "@sveltejs/adapter-cloudflare";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// stop traversing this node
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
|
|
43
|
+
|
|
44
|
+
// If using typescript, add the platform interface to the `App` interface
|
|
45
|
+
if (usesTypescript(ctx)) {
|
|
46
|
+
transformFile("src/app.d.ts", {
|
|
47
|
+
visitTSModuleDeclaration(n) {
|
|
48
|
+
if (n.value.id.name === "App") {
|
|
49
|
+
const patchAst = parseTs(platformInterface);
|
|
50
|
+
const body = n.node.body as recast.types.namedTypes.TSModuleBlock;
|
|
51
|
+
body.body.push(patchAst.program.body[0]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.traverse(n);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const config: TemplateConfig = {
|
|
62
|
+
configVersion: 1,
|
|
63
|
+
id: "svelte",
|
|
64
|
+
displayName: "Svelte",
|
|
65
|
+
platform: "pages",
|
|
66
|
+
generate,
|
|
67
|
+
configure,
|
|
68
|
+
transformPackageJson: async () => ({
|
|
69
|
+
scripts: {
|
|
70
|
+
"pages:preview": `${npm} run build && wrangler pages dev ${await compatDateFlag()} .svelte-kit/cloudflare`,
|
|
71
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
devScript: "dev",
|
|
75
|
+
previewScript: "pages:preview",
|
|
76
|
+
};
|
|
77
|
+
export default config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const platformInterface = `
|
|
2
|
+
interface Platform {
|
|
3
|
+
env: {
|
|
4
|
+
COUNTER: DurableObjectNamespace;
|
|
5
|
+
};
|
|
6
|
+
context: {
|
|
7
|
+
waitUntil(promise: Promise<any>): void;
|
|
8
|
+
};
|
|
9
|
+
caches: CacheStorage & { default: Cache }
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
// interface["Platform"] #context #waitUntil:nth(2)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
2
|
+
import { compatDateFlag } from "helpers/files";
|
|
3
|
+
import { detectPackageManager } from "helpers/packages";
|
|
4
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
5
|
+
import type { C3Context } from "types";
|
|
6
|
+
|
|
7
|
+
const { npm } = detectPackageManager();
|
|
8
|
+
|
|
9
|
+
const generate = async (ctx: C3Context) => {
|
|
10
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const config: TemplateConfig = {
|
|
14
|
+
configVersion: 1,
|
|
15
|
+
id: "vue",
|
|
16
|
+
displayName: "Vue",
|
|
17
|
+
platform: "pages",
|
|
18
|
+
generate,
|
|
19
|
+
transformPackageJson: async () => ({
|
|
20
|
+
scripts: {
|
|
21
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 5173 -- ${npm} run dev`,
|
|
22
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
testFlags: ["--ts"],
|
|
26
|
+
};
|
|
27
|
+
export default config;
|
|
Binary file
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Example ChatGPT Plugin for Cloudflare Workers
|
|
2
|
-
|
|
3
|
-
This is an example plugin showing how to build [ChatGPT plugins](https://platform.openai.com/docs/plugins/introduction) using [Cloudflare Workers](https://workers.dev). Using this example, you can deploy a plugin to Cloudflare Workers in just a few minutes.
|
|
4
|
-
|
|
5
|
-
The sample plugin allows ChatGPT users to search for repositories using GitHub's search API. The plugin is implemented in TypeScript and uses the [OpenAPI](https://www.openapis.org/) specification to define the plugin's API.
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
## Get started
|
|
10
|
-
|
|
11
|
-
0. Sign up for [Cloudflare Workers](https://workers.dev). The free tier is more than enough for most use cases.
|
|
12
|
-
1. Install [wrangler](https://developers.cloudflare.com/workers/cli-wrangler/install-update), the Cloudflare Workers CLI
|
|
13
|
-
2. Clone this project and install dependencies with `npm install`
|
|
14
|
-
3. Run `wrangler login` to login to your Cloudflare account in wrangler
|
|
15
|
-
4. Run `wrangler deploy` to publish the plugin to Cloudflare Workers
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
1. You can configure the `.well-known/ai-plugin.json` route in `index.ts`.
|
|
20
|
-
2. You can set up any new routes and the associated OpenAPI schema by defining new routes. See `search.ts` for an example.
|
|
21
|
-
3. For more information read the [itty-router-openapi official documentation](https://cloudflare.github.io/itty-router-openapi/).
|
|
22
|
-
|
|
23
|
-
## Deploying to OpenAI's API
|
|
24
|
-
|
|
25
|
-
Follow the instructions [in the ChatGPT documentation](https://platform.openai.com/docs/plugins/introduction/plugin-flow) to deploy your plugin and begin using it in ChatGPT.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cloudflare-workers-chatgpt-plugin-example",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"private": true,
|
|
5
|
-
"scripts": {
|
|
6
|
-
"deploy": "wrangler deploy",
|
|
7
|
-
"dev": "wrangler dev",
|
|
8
|
-
"start": "wrangler dev"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"@cloudflare/itty-router-openapi": "^1.0.1"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@cloudflare/workers-types": "^4.20230404.0",
|
|
15
|
-
"wrangler": "^3.0.0"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { OpenAPIRouter } from "@cloudflare/itty-router-openapi";
|
|
2
|
-
import { GetSearch } from "./search";
|
|
3
|
-
|
|
4
|
-
export const router = OpenAPIRouter({
|
|
5
|
-
schema: {
|
|
6
|
-
info: {
|
|
7
|
-
title: "GitHub Repositories Search API",
|
|
8
|
-
description:
|
|
9
|
-
"A plugin that allows the user to search for GitHub repositories using ChatGPT",
|
|
10
|
-
version: "v0.0.1",
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
docs_url: "/",
|
|
14
|
-
aiPlugin: {
|
|
15
|
-
name_for_human: "GitHub Repositories Search",
|
|
16
|
-
name_for_model: "github_repositories_search",
|
|
17
|
-
description_for_human: "GitHub Repositories Search plugin for ChatGPT.",
|
|
18
|
-
description_for_model:
|
|
19
|
-
"GitHub Repositories Search plugin for ChatGPT. You can search for GitHub repositories using this plugin.",
|
|
20
|
-
contact_email: "support@example.com",
|
|
21
|
-
legal_info_url: "http://www.example.com/legal",
|
|
22
|
-
logo_url: "https://workers.cloudflare.com/resources/logo/logo.svg",
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
router.get("/search", GetSearch);
|
|
27
|
-
|
|
28
|
-
// 404 for everything else
|
|
29
|
-
router.all("*", () => new Response("Not Found.", { status: 404 }));
|
|
30
|
-
|
|
31
|
-
export default {
|
|
32
|
-
fetch: router.handle,
|
|
33
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { OpenAPIRoute, Query } from "@cloudflare/itty-router-openapi";
|
|
2
|
-
|
|
3
|
-
export class GetSearch extends OpenAPIRoute {
|
|
4
|
-
static schema = {
|
|
5
|
-
tags: ["Search"],
|
|
6
|
-
summary: "Search repositories by a query parameter",
|
|
7
|
-
parameters: {
|
|
8
|
-
q: Query(String, {
|
|
9
|
-
description: "The query to search for",
|
|
10
|
-
default: "cloudflare workers",
|
|
11
|
-
}),
|
|
12
|
-
},
|
|
13
|
-
responses: {
|
|
14
|
-
"200": {
|
|
15
|
-
description: "Successfully response",
|
|
16
|
-
schema: {
|
|
17
|
-
repos: [
|
|
18
|
-
{
|
|
19
|
-
name: "itty-router-openapi",
|
|
20
|
-
description:
|
|
21
|
-
"OpenAPI 3 schema generator and validator for Cloudflare Workers",
|
|
22
|
-
stars: "80",
|
|
23
|
-
url: "https://github.com/cloudflare/itty-router-openapi",
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
async handle(request: Request, env, ctx, data: Record<string, any>) {
|
|
32
|
-
const url = `https://api.github.com/search/repositories?q=${data.query.q}`;
|
|
33
|
-
|
|
34
|
-
const resp = await fetch(url, {
|
|
35
|
-
headers: {
|
|
36
|
-
Accept: "application/vnd.github.v3+json",
|
|
37
|
-
"User-Agent": "RepoAI - Cloudflare Workers ChatGPT Plugin Example",
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (!resp.ok) {
|
|
42
|
-
return new Response(await resp.text(), { status: 400 });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const json = await resp.json();
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
const repos = json.items.map((item: any) => ({
|
|
49
|
-
name: item.name,
|
|
50
|
-
description: item.description,
|
|
51
|
-
stars: item.stargazers_count,
|
|
52
|
-
url: item.html_url,
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
repos: repos,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|