Skip to content

Commit

Permalink
Update release mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Dec 20, 2023
1 parent 8335734 commit 0758aac
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
42 changes: 42 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {ExecutionContext} from '@cloudflare/workers-types';
import {Environment} from './common';
import {Router} from './router';

const testEnvironment: Environment = {
__STATIC_CONTENT: {},
GITHUB_ACCESS_USER: 'testGithubAccessUser',
GITHUB_ACCESS_TOKEN: 'testGithubAccessToken',
CACHE: {
put() {
throw `Not implemented!`;
},
get() {
throw `Not implemented!`;
},
list() {
throw `Not implemented!`;
},
delete() {
throw `Not implemented!`;
},
// @ts-ignore
getWithMetadataetadata() {
throw `Not implemented!`;
},
},
};

const testContext: ExecutionContext = {
waitUntil(_promise) {

Check failure on line 30 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / Test

'_promise' is defined but never used
throw `Not implemented!`;
},
passThroughOnException() {
throw `Not implemented!`;
},
};

test('GET /', async () => {
const router = new Router({});
const result = await router.handle(new Request('http://falcon/all', {method: 'GET'}), testEnvironment, testContext);
expect(result.status).toBe(301);
});
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {ExecutionContext} from '@cloudflare/workers-types';

// @ts-ignore
import manifestJSON from '__STATIC_CONTENT_MANIFEST';
import {Environment} from './common';
import {AllHandler} from './handler_all';
import {DocumentHandler} from './handler_document';
Expand All @@ -7,7 +10,9 @@ import {LatestInfoHandler} from './handler_latest_info';
import {Releases} from './releases';
import {Router} from './router';

const router = new Router();
const assetManifest = JSON.parse(manifestJSON);

const router = new Router(assetManifest);
const releases = new Releases('echocat', 'caretakerd', router);
const documentHandler = new DocumentHandler(releases);
const downloadHandler = new DownloadHandler(releases);
Expand Down
8 changes: 2 additions & 6 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import {getAssetFromKV, NotFoundError} from '@cloudflare/kv-asset-handler';
import {ExecutionContext} from '@cloudflare/workers-types';
import {Environment} from './common';

// @ts-ignore
import manifestJSON from '__STATIC_CONTENT_MANIFEST';
const assetManifest = JSON.parse(manifestJSON);

interface Rule {
regexp: RegExp;
handler: (request: Request, env: Environment, match: RegExpMatchArray) => Promise<Response>;
Expand Down Expand Up @@ -35,7 +31,7 @@ export class Router {
},
];

constructor() {}
constructor(private assetManifest: any) {}

public onNotFound: (request: Request, env: Environment) => Promise<Response> = async (request, env) => {
return await this._defaultOnNotFound(request, env);
Expand Down Expand Up @@ -116,7 +112,7 @@ export class Router {
},
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: assetManifest,
ASSET_MANIFEST: this.assetManifest,
},
);
response.headers.set('Cache-Control', `public, max-age=3600, immutable`);
Expand Down

0 comments on commit 0758aac

Please sign in to comment.