diff --git a/src/routes/index.ts b/src/routes/index.ts index cbdd806..37fdd5a 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -3,6 +3,9 @@ // This software is released under the MIT License. // https://opensource.org/licenses/MIT +// import version from package.json +import { version } from '../../package.json'; + export default { async fetch(request, env): Promise { // Get the short code from the request URL. @@ -21,7 +24,7 @@ export default { if (request.method !== 'GET') return new Response('Method Not Allowed', { status: 405 }); // Show index page if no short code is provided. - if (!shortCodeGet) return new Response('just redirect. - powered by jqshuv x unately.', { status: 200 }); + if (!shortCodeGet) return new Response(`just redirect. (v${version}) - powered by jqshuv x unately.`, { status: 200 }); // Get the redirect URL from the short code. const data = await env.SHORT_URLS.get(shortCodeGet); diff --git a/test/index.spec.ts b/test/index.spec.ts index 9d0fc49..4b6f326 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -6,6 +6,7 @@ import { env, createExecutionContext, waitOnExecutionContext } from 'cloudflare:test'; import { describe, it, expect } from 'vitest'; import worker from '../src/index'; +import { version } from '../package.json'; const IncomingRequest = Request; @@ -19,7 +20,7 @@ describe('Hello World worker', () => { const response = await worker.fetch(request, env); // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions await waitOnExecutionContext(ctx); - expect(await response.text()).toMatchInlineSnapshot("\"just redirect. - powered by jqshuv x unately.\""); + expect(await response.text()).toMatchInlineSnapshot(`"just redirect. (v${version}) - powered by jqshuv x unately."`); }); it('post request url', async () => {