Skip to content

Commit bfda46e

Browse files
committed
0.0.1 更新
1 parent bc21663 commit bfda46e

10 files changed

+1288
-453
lines changed

.editorconfig

-12
This file was deleted.

.prettierrc

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2-
"printWidth": 140,
3-
"singleQuote": true,
4-
"semi": true,
5-
"useTabs": true
6-
}
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"printWidth": 110,
7+
"trailingComma": "none"
8+
}

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
2-
"name": "ona-prox",
3-
"version": "0.0.0",
42
"private": true,
53
"scripts": {
64
"deploy": "wrangler deploy",
75
"dev": "wrangler dev",
86
"start": "wrangler dev",
97
"test": "vitest",
10-
"cf-typegen": "wrangler types"
8+
"cf-typegen": "wrangler types",
9+
"format": "prettier --write src/"
1110
},
1211
"devDependencies": {
13-
"@cloudflare/vitest-pool-workers": "^0.5.2",
12+
"@cloudflare/vitest-pool-workers": "^0.5.20",
1413
"@cloudflare/workers-types": "^4.20241011.0",
15-
"typescript": "^5.5.2",
14+
"prettier": "^3.3.3",
15+
"typescript": "^5.6.3",
1616
"vitest": "2.0.5",
17-
"wrangler": "^3.60.3"
18-
}
17+
"wrangler": "^3.81.0"
18+
},
19+
"type": "module"
1920
}

pnpm-lock.yaml

+1,171-340
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
/**
2-
* Welcome to Cloudflare Workers! This is your first worker.
3-
*
4-
* - Run `npm run dev` in your terminal to start a development server
5-
* - Open a browser tab at http://localhost:8787/ to see your worker in action
6-
* - Run `npm run deploy` to publish your worker
7-
*
8-
* Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
9-
* `Env` object can be regenerated with `npm run cf-typegen`.
10-
*
11-
* Learn more at https://developers.cloudflare.com/workers/
12-
*/
13-
141
export default {
15-
async fetch(request, env, ctx): Promise<Response> {
16-
return new Response('Hello World!');
17-
},
18-
} satisfies ExportedHandler<Env>;
2+
async fetch(request): Promise<Response> {
3+
const url: URL = new URL(request.url)
4+
const pathname: string = url.pathname
5+
let hostname: string | undefined = pathname.split('/').filter(Boolean)[0]
6+
let referer: string | null = request.headers.get('Referer')
7+
8+
if (!hostname?.startsWith('~')) {
9+
hostname = '~i.pximg.net'
10+
referer = 'https://pixiv.net'
11+
}
12+
13+
url.pathname = pathname.replace(`/${hostname}`, '')
14+
url.hostname = hostname.slice(1)
15+
16+
return fetch(new Request(url, request), {
17+
headers: {
18+
...(referer && { Referer: referer })
19+
}
20+
})
21+
}
22+
} satisfies ExportedHandler<Env>

test/index.spec.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import worker from '../src/index';
88
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
99

1010
describe('Hello World worker', () => {
11-
it('responds with Hello World! (unit style)', async () => {
12-
const request = new IncomingRequest('http://example.com');
13-
// Create an empty context to pass to `worker.fetch()`.
14-
const ctx = createExecutionContext();
15-
const response = await worker.fetch(request, env, ctx);
16-
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
17-
await waitOnExecutionContext(ctx);
18-
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19-
});
11+
it('responds with Hello World! (unit style)', async () => {
12+
const request = new IncomingRequest('http://example.com');
13+
// Create an empty context to pass to `worker.fetch()`.
14+
const ctx = createExecutionContext();
15+
const response = await worker.fetch(request, env, ctx);
16+
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
17+
await waitOnExecutionContext(ctx);
18+
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19+
});
2020

21-
it('responds with Hello World! (integration style)', async () => {
22-
const response = await SELF.fetch('https://example.com');
23-
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
24-
});
21+
it('responds with Hello World! (integration style)', async () => {
22+
const response = await SELF.fetch('https://example.com');
23+
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
24+
});
2525
});

test/tsconfig.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"types": ["@cloudflare/workers-types/experimental", "@cloudflare/vitest-pool-workers"]
5-
},
6-
"include": ["./**/*.ts", "../src/env.d.ts"],
7-
"exclude": []
8-
}
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"types": [
5+
"@cloudflare/workers-types/experimental",
6+
"@cloudflare/vitest-pool-workers"
7+
]
8+
},
9+
"include": [
10+
"./**/*.ts",
11+
"../src/env.d.ts"
12+
],
13+
"exclude": []
14+
}

tsconfig.json

+45-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
{
2-
"compilerOptions": {
3-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4-
5-
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
6-
"target": "es2021",
7-
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
8-
"lib": ["es2021"],
9-
/* Specify what JSX code is generated. */
10-
"jsx": "react-jsx",
11-
12-
/* Specify what module code is generated. */
13-
"module": "es2022",
14-
/* Specify how TypeScript looks up a file from a given module specifier. */
15-
"moduleResolution": "Bundler",
16-
/* Specify type package names to be included without being referenced in a source file. */
17-
"types": [
18-
"@cloudflare/workers-types/2023-07-01"
19-
],
20-
/* Enable importing .json files */
21-
"resolveJsonModule": true,
22-
23-
/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
24-
"allowJs": true,
25-
/* Enable error reporting in type-checked JavaScript files. */
26-
"checkJs": false,
27-
28-
/* Disable emitting files from a compilation. */
29-
"noEmit": true,
30-
31-
/* Ensure that each file can be safely transpiled without relying on other imports. */
32-
"isolatedModules": true,
33-
/* Allow 'import x from y' when a module doesn't have a default export. */
34-
"allowSyntheticDefaultImports": true,
35-
/* Ensure that casing is correct in imports. */
36-
"forceConsistentCasingInFileNames": true,
37-
38-
/* Enable all strict type-checking options. */
39-
"strict": true,
40-
41-
/* Skip type checking all .d.ts files. */
42-
"skipLibCheck": true
43-
},
44-
"exclude": ["test"],
45-
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
46-
}
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4+
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
5+
"target": "es2021",
6+
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
7+
"lib": [
8+
"es2021"
9+
],
10+
/* Specify what JSX code is generated. */
11+
"jsx": "react-jsx",
12+
/* Specify what module code is generated. */
13+
"module": "es2022",
14+
/* Specify how TypeScript looks up a file from a given module specifier. */
15+
"moduleResolution": "Bundler",
16+
/* Specify type package names to be included without being referenced in a source file. */
17+
"types": [
18+
"@cloudflare/workers-types/2023-07-01"
19+
],
20+
/* Enable importing .json files */
21+
"resolveJsonModule": true,
22+
/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
23+
"allowJs": true,
24+
/* Enable error reporting in type-checked JavaScript files. */
25+
"checkJs": false,
26+
/* Disable emitting files from a compilation. */
27+
"noEmit": true,
28+
/* Ensure that each file can be safely transpiled without relying on other imports. */
29+
"isolatedModules": true,
30+
/* Allow 'import x from y' when a module doesn't have a default export. */
31+
"allowSyntheticDefaultImports": true,
32+
/* Ensure that casing is correct in imports. */
33+
"forceConsistentCasingInFileNames": true,
34+
/* Enable all strict type-checking options. */
35+
"strict": true,
36+
/* Skip type checking all .d.ts files. */
37+
"skipLibCheck": true
38+
},
39+
"exclude": [
40+
"test"
41+
],
42+
"include": [
43+
"worker-configuration.d.ts",
44+
"src/**/*.ts"
45+
]
46+
}

vitest.config.mts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
22

33
export default defineWorkersConfig({
4-
test: {
5-
poolOptions: {
6-
workers: {
7-
wrangler: { configPath: './wrangler.toml' },
8-
},
9-
},
10-
},
4+
test: {
5+
poolOptions: {
6+
workers: {
7+
wrangler: { configPath: './wrangler.toml' },
8+
},
9+
},
10+
},
1111
});

wrangler.toml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "ona-prox"
33
main = "src/index.ts"
44
compatibility_date = "2023-05-18"
55
compatibility_flags = ["nodejs_compat"]
6+
routes = [
7+
{ pattern = "prox.spacetimee.xyz", custom_domain = true }
8+
]
69

710
# Workers Logs
811
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/

0 commit comments

Comments
 (0)