Skip to content

Commit

Permalink
chore: normalize wrangler.toml files
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed May 3, 2022
1 parent ead0b88 commit e39b96e
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 105 deletions.
8 changes: 4 additions & 4 deletions worker-aws/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name = "aws-worker"
type = "webpack"
account_id = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""

[vars]
AWS_REGION = "us-west-2"
Expand Down
8 changes: 4 additions & 4 deletions worker-cobol/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name = "cobol-worker"
type = "webpack"
webpack_config = "webpack.config.js"

account_id = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""
38 changes: 21 additions & 17 deletions worker-durable-objects/src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
// Worker

export default {
/**
* Worker
* @type {ExportedHandler}
*/
const worker = {
async fetch(request, env) {
return await handleRequest(request, env);
},
};

async function handleRequest(request, env) {
let id = env.COUNTER.idFromName('A');
let obj = env.COUNTER.get(id);
let resp = await obj.fetch(request.url);
let count = await resp.text();
let id = env.COUNTER.idFromName('A');
let obj = env.COUNTER.get(id);
let resp = await obj.fetch(request.url);
let count = await resp.text();

return new Response("Durable Object 'A' count: " + count);
}
return new Response("Durable Object 'A' count: " + count);
}
};

// Durable Object
export default worker;

/**
* Durable Object
*/
export class Counter {
constructor(state, env) {
constructor(state) {
this.state = state;
}

// Handle HTTP requests from clients.
/**
* Handle HTTP requests from clients.
* @param {Request} request
*/
async fetch(request) {
// Apply requested action.
let url = new URL(request.url);
Expand Down
15 changes: 6 additions & 9 deletions worker-durable-objects/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
name = "worker"
# type = "javascript" is required to use the `[build]` section
type = "javascript"
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
account_id = ""
route = ""
zone_id = ""

[build.upload]
# Upload the code directly from the src directory.
dir = "src"
# The "modules" upload format is required for all projects that export a Durable Objects class
format = "modules"
main = "./index.mjs"
dir = "src"

[durable_objects]
bindings = [{name = "COUNTER", class_name = "Counter"}]

[[migrations]]
tag = "v1" # Should be unique for each entry
new_classes = ["Counter"]
new_classes = ["Counter"]
4 changes: 2 additions & 2 deletions worker-emscripten/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { resolve } = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const spawn = require('child_process').spawnSync;

module.exports = {
context: path.resolve(__dirname, '.'),
context: resolve(__dirname, '.'),
devtool: 'nosources-source-map',
entry: './index.js',
target: 'webworker',
Expand Down
11 changes: 6 additions & 5 deletions worker-emscripten/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name = "emscripten-template"
type = "webpack"
zone_id = ""
account_id = ""
route = ""
workers_dev = true
webpack_config = "webpack.config.js"

name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
16 changes: 12 additions & 4 deletions worker-mysql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Client } from './driver/mysql';

export default {
async fetch(request: Request, env, ctx: ExecutionContext) {
interface Bindings {
TUNNEL_HOST?: string;
CF_CLIENT_ID?: string;
CF_CLIENT_SECRET?: string;
}

const worker: ExportedHandler<Bindings> = {
async fetch(request, env, ctx) {
// Add Cloudflare Access Service Token credentials as global variables, used when Worker
// establishes the connection to Cloudflare Tunnel. This ensures only approved services can
// connect to your Tunnel.
Expand All @@ -28,8 +34,10 @@ export default {

// Return result from database.
return new Response(JSON.stringify({ result }));
} catch (e) {
return new Response((e as Error).message);
} catch (err) {
return new Response((err as Error).message);
}
},
};

export default worker;
11 changes: 6 additions & 5 deletions worker-mysql/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "worker-template-mysql"
type = "javascript"
account_id = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""

compatibility_date = "2021-10-07"

[build]
Expand All @@ -12,7 +13,7 @@ command = "npm install && npm run build && cp ./src/driver/**/*.wasm ./dist"
[build.upload]
format = "modules"
main = "./index.mjs"
dir = "./dist"
dir = "dist"

[[build.upload.rules]]
type = "CompiledWasm"
Expand Down
20 changes: 16 additions & 4 deletions worker-postgres/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { Client } from './driver/postgres';

export default {
async fetch(request: Request, env, ctx: ExecutionContext) {
interface Bindings {
CF_CLIENT_ID?: string;
CF_CLIENT_SECRET?: string;
}

declare global {
var CF_CLIENT_ID: string | undefined;
var CF_CLIENT_SECRET: string | undefined;
}

const worker: ExportedHandler<Bindings> = {
async fetch(request, env, ctx) {
// Add Cloudflare Access Service Token credentials as global variables, used when Worker
// establishes the connection to Cloudflare Tunnel. This ensures only approved services can
// connect to your Tunnel.
Expand Down Expand Up @@ -29,8 +39,10 @@ export default {

// Return result from database.
return new Response(JSON.stringify(result.rows[0]));
} catch (e) {
return new Response((e as Error).message);
} catch (err) {
return new Response((err as Error).message);
}
},
};

export default worker;
11 changes: 6 additions & 5 deletions worker-postgres/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "worker-template-postgres"
type = "javascript"
account_id = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""

compatibility_date = "2021-10-07"

[build]
Expand All @@ -12,7 +13,7 @@ command = "npm install && npm run build && cp ./src/driver/**/*.wasm ./dist"
[build.upload]
format = "modules"
main = "./index.mjs"
dir = "./dist"
dir = "dist"

[[build.upload.rules]]
type = "CompiledWasm"
Expand Down
7 changes: 3 additions & 4 deletions worker-router/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name = "router"
type = "webpack"
name = "<< todo >>"

account_id = ""
account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""
9 changes: 5 additions & 4 deletions worker-rust/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name = "{{project-name}}"
type = "javascript"
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true

compatibility_date = "2022-01-20"

[vars]
Expand All @@ -17,6 +21,3 @@ main = "./shim.mjs"
[[build.upload.rules]]
globs = ["**/*.wasm"]
type = "CompiledWasm"

# read more about configuring your Worker via wrangler.toml at:
# https://developers.cloudflare.com/workers/cli-wrangler/configuration
8 changes: 4 additions & 4 deletions worker-sites-react/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
account_id = "dc56444c4c955a1653106ccf997c1067"
name = "my-react-app"
type = "webpack"
route = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
zone_id = ""

[site]
bucket = "./build"
Expand Down
10 changes: 7 additions & 3 deletions worker-sites/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
account_id = ""
name = "my-site"
type = "webpack"
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
site = { bucket = "./public" }

[site]
bucket = "./public"
7 changes: 4 additions & 3 deletions worker-speedtest/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type = "webpack"
zone_id = ""
account_id = ""
route = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
11 changes: 6 additions & 5 deletions worker-typescript/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name = "worker-typescript-template"
type = "javascript"
zone_id = ""
account_id = ""
route = ""
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true

[build]
command = "npm install && npm run build"
command = "npm run build"

[build.upload]
format = "service-worker"
8 changes: 4 additions & 4 deletions worker-websocket/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "websocket-template"
type = "webpack"
account_id = "b54f07a6c269ecca2fa60f1ae4920c99"
name = "<< todo >>"

account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""
13 changes: 0 additions & 13 deletions worker/index.js

This file was deleted.

3 changes: 1 addition & 2 deletions worker/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"private": true,
"version": "0.0.0",
"main": "index.js"
"version": "0.0.0"
}
14 changes: 14 additions & 0 deletions worker/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @type {ExportedHandler}
*/
const worker = {
fetch(request) {
return new Response('Hello worker!', {
headers: {
'content-type': 'text/plain'
}
});
}
};

export default worker;
12 changes: 8 additions & 4 deletions worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name = "helloworld"
type = "javascript"
name = "<< todo >>"

account_id = ""
account_id = "<< todo >>"
zone_id = "<< todo >>"
workers_dev = true
route = ""
zone_id = ""

[build.upload]
format = "modules"
main = "./index.mjs"
dir = "src"

0 comments on commit e39b96e

Please sign in to comment.