create-cloudflare 0.0.0-e33bb44a → 0.0.0-e3990bbf
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/README.md +1 -1
- package/dist/cli.js +43232 -42461
- package/package.json +81 -73
- package/templates/chatgptPlugin/ts/README.md +2 -2
- package/templates/chatgptPlugin/ts/package.json +1 -1
- package/templates/chatgptPlugin/ts/src/search.ts +3 -7
- package/templates/common/js/package.json +0 -1
- package/templates/common/js/wrangler.toml +1 -1
- package/templates/common/ts/wrangler.toml +1 -1
- package/templates/hello-world/js/package.json +0 -2
- package/templates/hello-world/js/wrangler.toml +1 -1
- package/templates/hello-world/ts/wrangler.toml +1 -1
- package/templates/openapi/ts/README.md +25 -0
- package/templates/openapi/ts/package.json +18 -0
- package/templates/openapi/ts/src/endpoints/taskCreate.ts +48 -0
- package/templates/openapi/ts/src/endpoints/taskDelete.ts +55 -0
- package/templates/openapi/ts/src/endpoints/taskFetch.ts +74 -0
- package/templates/openapi/ts/src/endpoints/taskList.ts +66 -0
- package/templates/openapi/ts/src/index.ts +29 -0
- package/templates/openapi/ts/src/types.ts +9 -0
- package/templates/openapi/ts/tsconfig.json +32 -0
- package/templates/openapi/ts/wrangler.toml +3 -0
- package/templates/queues/js/package.json +0 -2
- package/templates/queues/js/wrangler.toml +3 -3
- package/templates/queues/ts/wrangler.toml +3 -3
- package/templates/scheduled/js/package.json +0 -2
- package/templates/scheduled/js/wrangler.toml +1 -1
- package/templates/scheduled/ts/wrangler.toml +1 -1
- /package/templates/common/js/src/{worker.js → index.js} +0 -0
- /package/templates/common/ts/src/{worker.ts → index.ts} +0 -0
- /package/templates/hello-world/js/src/{worker.js → index.js} +0 -0
- /package/templates/hello-world/ts/src/{worker.ts → index.ts} +0 -0
- /package/templates/queues/js/src/{worker.js → index.js} +0 -0
- /package/templates/queues/ts/src/{worker.ts → index.ts} +0 -0
- /package/templates/scheduled/js/src/{worker.js → index.js} +0 -0
- /package/templates/scheduled/ts/src/{worker.ts → index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,74 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
2
|
+
"name": "create-cloudflare",
|
|
3
|
+
"version": "0.0.0-e3990bbf",
|
|
4
|
+
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"workers",
|
|
8
|
+
"cloudflare workers",
|
|
9
|
+
"serverless",
|
|
10
|
+
"serverless application"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cloudflare/workers-sdk.git",
|
|
15
|
+
"directory": "packages/create-cloudflare"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT OR Apache-2.0",
|
|
18
|
+
"author": "wrangler@cloudflare.com",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/cli.js",
|
|
23
|
+
"bin": "./dist/cli.js",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"templates"
|
|
27
|
+
],
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/parser": "^7.21.3",
|
|
30
|
+
"@babel/types": "^7.21.4",
|
|
31
|
+
"@clack/prompts": "^0.6.3",
|
|
32
|
+
"@cloudflare/eslint-config-worker": "*",
|
|
33
|
+
"@cloudflare/workers-types": "^4.20230419.0",
|
|
34
|
+
"@types/command-exists": "^1.2.0",
|
|
35
|
+
"@types/cross-spawn": "^6.0.2",
|
|
36
|
+
"@types/dns2": "^2.0.3",
|
|
37
|
+
"@types/esprima": "^4.0.3",
|
|
38
|
+
"@types/node": "^18.15.3",
|
|
39
|
+
"@types/which-pm-runs": "^1.0.0",
|
|
40
|
+
"@types/yargs": "^17.0.22",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
43
|
+
"chalk": "^5.2.0",
|
|
44
|
+
"command-exists": "^1.2.9",
|
|
45
|
+
"cross-spawn": "^7.0.3",
|
|
46
|
+
"dns2": "^2.1.0",
|
|
47
|
+
"esbuild": "^0.17.12",
|
|
48
|
+
"execa": "^7.1.1",
|
|
49
|
+
"haikunator": "^2.1.2",
|
|
50
|
+
"log-update": "^5.0.1",
|
|
51
|
+
"open": "^8.4.0",
|
|
52
|
+
"pnpm": "^8.6.11",
|
|
53
|
+
"recast": "^0.22.0",
|
|
54
|
+
"semver": "^7.5.1",
|
|
55
|
+
"typescript": "^5.0.2",
|
|
56
|
+
"undici": "5.20.0",
|
|
57
|
+
"vite-tsconfig-paths": "^4.0.8",
|
|
58
|
+
"vitest": "^0.30.0",
|
|
59
|
+
"which-pm-runs": "^1.1.0",
|
|
60
|
+
"yargs": "^17.7.1",
|
|
61
|
+
"yarn": "^1.22.19",
|
|
62
|
+
"@clack/core": "^0.3.2",
|
|
63
|
+
"@types/semver": "^7.5.1",
|
|
64
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
65
|
+
"wrangler": "3.8.0"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=16.13.0"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "node -r esbuild-register scripts/build.ts",
|
|
72
|
+
"check:lint": "eslint .",
|
|
73
|
+
"check:type": "tsc",
|
|
74
|
+
"lint": "eslint",
|
|
75
|
+
"test:e2e:cleanup": "node -r esbuild-register scripts/e2eCleanup.ts",
|
|
76
|
+
"test:e2e:npm": "pnpm run build && TEST_PM=npm vitest run --config ./vitest-e2e.config.ts",
|
|
77
|
+
"test:e2e:pnpm": "pnpm run build && TEST_PM=pnpm vitest run --config ./vitest-e2e.config.ts",
|
|
78
|
+
"test:unit": "vitest run --config ./vitest.config.ts",
|
|
79
|
+
"test:unit:watch": "vitest --config ./vitest.config.ts",
|
|
80
|
+
"watch": "node -r esbuild-register scripts/build.ts --watch"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -17,8 +17,8 @@ The sample plugin allows ChatGPT users to search for repositories using GitHub's
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
1. You can configure the `.well-known/ai-plugin.json` route in `index.ts`.
|
|
20
|
-
2.
|
|
21
|
-
3.
|
|
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
22
|
|
|
23
23
|
## Deploying to OpenAI's API
|
|
24
24
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiException,
|
|
3
|
-
OpenAPIRoute,
|
|
4
|
-
Query,
|
|
5
|
-
ValidationError,
|
|
6
|
-
} from "@cloudflare/itty-router-openapi";
|
|
1
|
+
import { OpenAPIRoute, Query } from "@cloudflare/itty-router-openapi";
|
|
7
2
|
|
|
8
3
|
export class GetSearch extends OpenAPIRoute {
|
|
9
4
|
static schema = {
|
|
@@ -17,6 +12,7 @@ export class GetSearch extends OpenAPIRoute {
|
|
|
17
12
|
},
|
|
18
13
|
responses: {
|
|
19
14
|
"200": {
|
|
15
|
+
description: "Successfully response",
|
|
20
16
|
schema: {
|
|
21
17
|
repos: [
|
|
22
18
|
{
|
|
@@ -33,7 +29,7 @@ export class GetSearch extends OpenAPIRoute {
|
|
|
33
29
|
};
|
|
34
30
|
|
|
35
31
|
async handle(request: Request, env, ctx, data: Record<string, any>) {
|
|
36
|
-
const url = `https://api.github.com/search/repositories?q=${data.q}`;
|
|
32
|
+
const url = `https://api.github.com/search/repositories?q=${data.query.q}`;
|
|
37
33
|
|
|
38
34
|
const resp = await fetch(url, {
|
|
39
35
|
headers: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Cloudflare Workers OpenAPI 3.1
|
|
2
|
+
|
|
3
|
+
This is a Cloudflare Worker with OpenAPI 3.1 using [itty-router-openapi](https://github.com/cloudflare/itty-router-openapi).
|
|
4
|
+
|
|
5
|
+
This is an example project made to be used as a quick start into building OpenAPI compliant Workers that generates the
|
|
6
|
+
`openapi.json` schema automatically from code and validates the incoming request to the defined parameters or request body.
|
|
7
|
+
|
|
8
|
+
## Get started
|
|
9
|
+
|
|
10
|
+
1. Sign up for [Cloudflare Workers](https://workers.dev). The free tier is more than enough for most use cases.
|
|
11
|
+
2. Clone this project and install dependencies with `npm install`
|
|
12
|
+
3. Run `wrangler login` to login to your Cloudflare account in wrangler
|
|
13
|
+
4. Run `wrangler deploy` to publish the API to Cloudflare Workers
|
|
14
|
+
|
|
15
|
+
## Project structure
|
|
16
|
+
|
|
17
|
+
1. Your main router is defined in `src/index.ts`.
|
|
18
|
+
2. Each endpoint has its own file in `src/endpoints/`.
|
|
19
|
+
3. For more information read the [itty-router-openapi official documentation](https://cloudflare.github.io/itty-router-openapi/).
|
|
20
|
+
|
|
21
|
+
## Development
|
|
22
|
+
|
|
23
|
+
1. Run `wrangler dev` to start a local instance of the API.
|
|
24
|
+
2. Open `http://localhost:9000/` in your browser to see the Swagger interface where you can try the endpoints.
|
|
25
|
+
3. Changes made in the `src/` folder will automatically trigger the server to reload, you only need to refresh the Swagger interface.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cloudflare-workers-openapi",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"deploy": "wrangler deploy",
|
|
7
|
+
"start": "wrangler dev"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@cloudflare/itty-router-openapi": "^1.0.1"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@cloudflare/workers-types": "^4.20230821.0",
|
|
14
|
+
"@types/node": "^20.5.7",
|
|
15
|
+
"@types/service-worker-mock": "^2.0.1",
|
|
16
|
+
"wrangler": "^3.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIRoute,
|
|
3
|
+
OpenAPIRouteSchema,
|
|
4
|
+
} from "@cloudflare/itty-router-openapi";
|
|
5
|
+
import { Task } from "../types";
|
|
6
|
+
|
|
7
|
+
export class TaskCreate extends OpenAPIRoute {
|
|
8
|
+
static schema: OpenAPIRouteSchema = {
|
|
9
|
+
tags: ["Tasks"],
|
|
10
|
+
summary: "Create a new Task",
|
|
11
|
+
requestBody: Task,
|
|
12
|
+
responses: {
|
|
13
|
+
"200": {
|
|
14
|
+
description: "Returns the created task",
|
|
15
|
+
schema: {
|
|
16
|
+
success: Boolean,
|
|
17
|
+
result: {
|
|
18
|
+
task: Task,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async handle(
|
|
26
|
+
request: Request,
|
|
27
|
+
env: any,
|
|
28
|
+
context: any,
|
|
29
|
+
data: Record<string, any>
|
|
30
|
+
) {
|
|
31
|
+
// Retrieve the validated request body
|
|
32
|
+
const taskToCreate = data.body;
|
|
33
|
+
|
|
34
|
+
// Implement your own object insertion here
|
|
35
|
+
|
|
36
|
+
// return the new task
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
task: {
|
|
40
|
+
name: taskToCreate.name,
|
|
41
|
+
slug: taskToCreate.slug,
|
|
42
|
+
description: taskToCreate.description,
|
|
43
|
+
completed: taskToCreate.completed,
|
|
44
|
+
due_date: taskToCreate.due_date,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIRoute,
|
|
3
|
+
OpenAPIRouteSchema,
|
|
4
|
+
Path,
|
|
5
|
+
} from "@cloudflare/itty-router-openapi";
|
|
6
|
+
import { Task } from "../types";
|
|
7
|
+
|
|
8
|
+
export class TaskDelete extends OpenAPIRoute {
|
|
9
|
+
static schema: OpenAPIRouteSchema = {
|
|
10
|
+
tags: ["Tasks"],
|
|
11
|
+
summary: "Delete a Task",
|
|
12
|
+
parameters: {
|
|
13
|
+
taskSlug: Path(String, {
|
|
14
|
+
description: "Task slug",
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
responses: {
|
|
18
|
+
"200": {
|
|
19
|
+
description: "Returns if the task was deleted successfully",
|
|
20
|
+
schema: {
|
|
21
|
+
success: Boolean,
|
|
22
|
+
result: {
|
|
23
|
+
task: Task,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
async handle(
|
|
31
|
+
request: Request,
|
|
32
|
+
env: any,
|
|
33
|
+
context: any,
|
|
34
|
+
data: Record<string, any>
|
|
35
|
+
) {
|
|
36
|
+
// Retrieve the validated slug
|
|
37
|
+
const { taskSlug } = data.params;
|
|
38
|
+
|
|
39
|
+
// Implement your own object deletion here
|
|
40
|
+
|
|
41
|
+
// Return the deleted task for confirmation
|
|
42
|
+
return {
|
|
43
|
+
result: {
|
|
44
|
+
task: {
|
|
45
|
+
name: "Build something awesome with Cloudflare Workers",
|
|
46
|
+
slug: taskSlug,
|
|
47
|
+
description: "Lorem Ipsum",
|
|
48
|
+
completed: true,
|
|
49
|
+
due_date: "2022-12-24",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
success: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIRoute,
|
|
3
|
+
OpenAPIRouteSchema,
|
|
4
|
+
Path,
|
|
5
|
+
} from "@cloudflare/itty-router-openapi";
|
|
6
|
+
import { Task } from "../types";
|
|
7
|
+
|
|
8
|
+
export class TaskFetch extends OpenAPIRoute {
|
|
9
|
+
static schema: OpenAPIRouteSchema = {
|
|
10
|
+
tags: ["Tasks"],
|
|
11
|
+
summary: "Get a single Task by slug",
|
|
12
|
+
parameters: {
|
|
13
|
+
taskSlug: Path(String, {
|
|
14
|
+
description: "Task slug",
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
responses: {
|
|
18
|
+
"200": {
|
|
19
|
+
description: "Returns a single task if found",
|
|
20
|
+
schema: {
|
|
21
|
+
success: Boolean,
|
|
22
|
+
result: {
|
|
23
|
+
task: Task,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
"404": {
|
|
28
|
+
description: "Task not found",
|
|
29
|
+
schema: {
|
|
30
|
+
success: Boolean,
|
|
31
|
+
error: String,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async handle(
|
|
38
|
+
request: Request,
|
|
39
|
+
env: any,
|
|
40
|
+
context: any,
|
|
41
|
+
data: Record<string, any>
|
|
42
|
+
) {
|
|
43
|
+
// Retrieve the validated slug
|
|
44
|
+
const { taskSlug } = data.params;
|
|
45
|
+
|
|
46
|
+
// Implement your own object fetch here
|
|
47
|
+
|
|
48
|
+
const exists = true;
|
|
49
|
+
|
|
50
|
+
// @ts-ignore: check if the object exists
|
|
51
|
+
if (exists === false) {
|
|
52
|
+
return Response.json(
|
|
53
|
+
{
|
|
54
|
+
success: false,
|
|
55
|
+
error: "Object not found",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
status: 404,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
task: {
|
|
66
|
+
name: "my task",
|
|
67
|
+
slug: taskSlug,
|
|
68
|
+
description: "this needs to be done",
|
|
69
|
+
completed: false,
|
|
70
|
+
due_date: new Date().toISOString().slice(0, 10),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Task } from "../types";
|
|
2
|
+
import {
|
|
3
|
+
OpenAPIRoute,
|
|
4
|
+
OpenAPIRouteSchema,
|
|
5
|
+
Query,
|
|
6
|
+
} from "@cloudflare/itty-router-openapi";
|
|
7
|
+
|
|
8
|
+
export class TaskList extends OpenAPIRoute {
|
|
9
|
+
static schema: OpenAPIRouteSchema = {
|
|
10
|
+
tags: ["Tasks"],
|
|
11
|
+
summary: "List Tasks",
|
|
12
|
+
parameters: {
|
|
13
|
+
page: Query(Number, {
|
|
14
|
+
description: "Page number",
|
|
15
|
+
default: 0,
|
|
16
|
+
}),
|
|
17
|
+
isCompleted: Query(Boolean, {
|
|
18
|
+
description: "Filter by completed flag",
|
|
19
|
+
required: false,
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
responses: {
|
|
23
|
+
"200": {
|
|
24
|
+
description: "Returns a list of tasks",
|
|
25
|
+
schema: {
|
|
26
|
+
success: Boolean,
|
|
27
|
+
result: {
|
|
28
|
+
tasks: [Task],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async handle(
|
|
36
|
+
request: Request,
|
|
37
|
+
env: any,
|
|
38
|
+
context: any,
|
|
39
|
+
data: Record<string, any>
|
|
40
|
+
) {
|
|
41
|
+
// Retrieve the validated parameters
|
|
42
|
+
const { page, isCompleted } = data.query;
|
|
43
|
+
|
|
44
|
+
// Implement your own object list here
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
success: true,
|
|
48
|
+
tasks: [
|
|
49
|
+
{
|
|
50
|
+
name: "Clean my room",
|
|
51
|
+
slug: "clean-room",
|
|
52
|
+
description: null,
|
|
53
|
+
completed: false,
|
|
54
|
+
due_date: "2025-01-05",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "Build something awesome with Cloudflare Workers",
|
|
58
|
+
slug: "cloudflare-workers",
|
|
59
|
+
description: "Lorem Ipsum",
|
|
60
|
+
completed: true,
|
|
61
|
+
due_date: "2022-12-24",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OpenAPIRouter } from "@cloudflare/itty-router-openapi";
|
|
2
|
+
import { TaskList } from "./endpoints/taskList";
|
|
3
|
+
import { TaskCreate } from "./endpoints/taskCreate";
|
|
4
|
+
import { TaskFetch } from "./endpoints/taskFetch";
|
|
5
|
+
import { TaskDelete } from "./endpoints/taskDelete";
|
|
6
|
+
|
|
7
|
+
export const router = OpenAPIRouter({
|
|
8
|
+
docs_url: "/",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
router.get("/api/tasks/", TaskList);
|
|
12
|
+
router.post("/api/tasks/", TaskCreate);
|
|
13
|
+
router.get("/api/tasks/:taskSlug/", TaskFetch);
|
|
14
|
+
router.delete("/api/tasks/:taskSlug/", TaskDelete);
|
|
15
|
+
|
|
16
|
+
// 404 for everything else
|
|
17
|
+
router.all("*", () =>
|
|
18
|
+
Response.json(
|
|
19
|
+
{
|
|
20
|
+
success: false,
|
|
21
|
+
error: "Route not found",
|
|
22
|
+
},
|
|
23
|
+
{ status: 404 }
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
fetch: router.handle,
|
|
29
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"baseUrl": "src",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"inlineSourceMap": false,
|
|
10
|
+
"lib": ["esnext"],
|
|
11
|
+
"listEmittedFiles": false,
|
|
12
|
+
"listFiles": false,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"pretty": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"rootDir": ".",
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"strict": false,
|
|
20
|
+
"traceResolution": false,
|
|
21
|
+
"outDir": "",
|
|
22
|
+
"target": "esnext",
|
|
23
|
+
"module": "esnext",
|
|
24
|
+
"types": [
|
|
25
|
+
"@types/node",
|
|
26
|
+
"@types/service-worker-mock",
|
|
27
|
+
"@cloudflare/workers-types"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"exclude": ["node_modules", "dist", "tests"],
|
|
31
|
+
"include": ["src", "scripts"]
|
|
32
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
name = "<TBD>"
|
|
2
|
-
main = "src/
|
|
2
|
+
main = "src/index.js"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
4
|
|
|
5
5
|
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
6
6
|
# Docs: https://developers.cloudflare.com/queues/get-started
|
|
7
|
-
|
|
7
|
+
[[queues.producers]]
|
|
8
8
|
binding = "MY_QUEUE"
|
|
9
9
|
queue = "my-queue"
|
|
10
10
|
|
|
11
11
|
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
12
12
|
# Docs: https://developers.cloudflare.com/queues/get-started
|
|
13
|
-
|
|
13
|
+
[[queues.consumers]]
|
|
14
14
|
queue = "my-queue"
|
|
15
15
|
# Optional: Configure batching and retries: https://developers.cloudflare.com/queues/learning/batching-retries/
|
|
16
16
|
# max_batch_size = 10
|