Skip to content

Commit

Permalink
add cf worker hello world project and enable deploy via GITHUB action (
Browse files Browse the repository at this point in the history
…zizifn#78)

add cf worker hello world project and enable deploy via GITHUB action
  • Loading branch information
zizifn authored Dec 17, 2022
1 parent 4ebdf18 commit 4107bfc
Show file tree
Hide file tree
Showing 13 changed files with 16,600 additions and 11,427 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/cf-worker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: cf-worker-deploy

on:
push:
branches:
- main
- test-cf
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
environment: CF
name: Deploy
steps:
- uses: actions/checkout@v2
- name: envsubst
run: |
envsubst < apps/cf-worker-vless/wrangler.toml.tp > apps/cf-worker-vless/wrangler.toml
if [[ $CUSTOM_DOMAIN ]]; then
echo cf_environment="custom" >> $GITHUB_ENV
else
echo "not set CUSTOM_DOMAIN"
fi
env:
CUSTOM_DOMAIN: ${{ secrets.CUSTOM_DOMAIN }}
- name: Publish
uses: cloudflare/wrangler-action@2.0.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: publish --env ${{ env.cf_environment || 'default' }}
workingDirectory: 'apps/cf-worker-vless'
environment: ${{ env.cf_environment || 'default' }}
secrets: |
UUID
env:
UUID: ${{ secrets.UUID }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ Thumbs.db
**/config-local.json

**/.env

**/.dev.vars
**/wrangler.toml
18 changes: 18 additions & 0 deletions apps/cf-worker-vless/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
23 changes: 23 additions & 0 deletions apps/cf-worker-vless/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cf-worker-vless",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/cf-worker-vless/src",
"projectType": "application",
"targets": {
"serve": {
"executor": "nx:run-commands",
"options": {
"command": "wrangler dev",
"cwd": "apps/cf-worker-vless"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/cf-worker-vless/**/*.ts"]
}
}
},
"tags": []
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions apps/cf-worker-vless/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true,
};
3 changes: 3 additions & 0 deletions apps/cf-worker-vless/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: false,
};
9 changes: 9 additions & 0 deletions apps/cf-worker-vless/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
async fetch(request: Request, env: any) {
return new Response(
`request method111: ${request.method}, and env is ${JSON.stringify(
env
)} ${Date()}`
);
},
};
22 changes: 22 additions & 0 deletions apps/cf-worker-vless/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"module": "esnext",
"target": "es2020",
"lib": ["es2020"],
"strict": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"moduleResolution": "node",
"sourceMap": true,
"types": ["@cloudflare/workers-types", "@types/jest"]
},
"include": ["src"],
"exclude": ["node_modules", "dist", "test"],
"references": [
{
"path": "./tsconfig.app.json"
}
]
}
21 changes: 21 additions & 0 deletions apps/cf-worker-vless/wrangler.toml.tp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = "edge-tunnel-vless" # todo
main = "./src/main.ts"
compatibility_date = "2022-05-03"
workers_dev = true # should be deployed to *.workers.dev

[vars]
TEST_VAR = "example_dev_token"

[env.default]
name = "edge-tunnel-vless"
workers_dev = true # should be deployed to *.workers.dev

[env.default.vars]
TEST_VAR = "TEST_VAR_DEFAULT"

[env.custom]
name = "edge-tunnel-vless"
routes = [{ pattern = "$CUSTOM_DOMAIN", custom_domain = true }]

[env.custom.vars]
TEST_VAR = "TEST_VAR_CUSTOM"
Loading

0 comments on commit 4107bfc

Please sign in to comment.