diff --git a/src/config.js b/src/config.js index fcee8ad..09772e2 100644 --- a/src/config.js +++ b/src/config.js @@ -56,13 +56,7 @@ function fetchConfig() { // how many visitors should be let in at a time? // // default 5 - automaticQuantity: 5, - - // for demonstration purposes only, how many visitors should be - // added to the queue ahead of a new visitor - // - // default 15, set to 1 for normal behaviour - demoPadding: 15, + automaticQuantity: 5 }, }; } diff --git a/src/index.js b/src/index.js index 23fa8e3..1f82eaf 100644 --- a/src/index.js +++ b/src/index.js @@ -27,10 +27,6 @@ const textDecoder = new TextDecoder(); const adminView = textDecoder.decode(includeBytes('src/views/admin.html')); const queueView = textDecoder.decode(includeBytes('src/views/queue.html')); -// For demo purposes -const demoManifest = textDecoder.decode(includeBytes('src/static/demo-manifest.md')); -const DEMO_THUMBNAIL = includeBytes('src/static/demo-thumb.png'); - // The name of the backend serving the content that is being protected by the queue. const CONTENT_BACKEND = "protected_content"; @@ -54,22 +50,6 @@ async function handleRequest(event) { const { request, client } = event; const url = new URL(request.url); - // Metadata foe developer.fastly.com. - // Feel free to delete this. - if (url.pathname == "/.well-known/fastly/demo-manifest") { - return new Response(demoManifest, { - status: 200, - headers: { - "Content-Type": "text/markdown", - }, - }); - } else if (url.pathname == "/demo-thumb.png") { - return new Response(DEMO_THUMBNAIL, { - status: 200, - headers: { 'content-type': 'image/png' } - }); - } - // Allow requests to assets that are not protected by the queue. if (ALLOWED_PATHS.includes(url.pathname)) { let resp = await handleAuthorizedRequest(request); @@ -124,11 +104,10 @@ async function handleRequest(event) { if (payload && isValid) { visitorPosition = payload.position; } else { - // Add a new visitor to the end of the queue. - // If demo padding is set in the config, the queue will grow by that amount. + // Add 1 new visitor to the end of the queue. visitorPosition = await incrementQueueLength( redis, - config.queue.demoPadding ? config.queue.demoPadding : 1 + 1 ); // Sign a JWT with the visitor's position. diff --git a/src/static/demo-manifest.md b/src/static/demo-manifest.md deleted file mode 100644 index 4a10902..0000000 --- a/src/static/demo-manifest.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -schemaVersion: 1 -id: compute-stateful-queue -title: Stateful queue (JavaScript) -description: | - Using a third-party Redis API provider as a lightweight store, issue - website visitors with a place in an orderly queue, and admit them to the - website in a way that regulates load on your origin infrastructure. -repo: https://github.com/fastly/compute-starter-kit-javascript-queue -image: - href: /demo-thumb.png - alt: Holding page for a waiting room -expectedRootStatus: 401 -views: - endUser: - mode: frame - href: /index.html - height: 550 - superUser: - mode: frame - href: /_queue - height: 60 -sessions: false ---- - -When a visitor makes a request for the first time, we generate a signed JWT containing their _position_ in the queue, which is determined by fetching the current queue _length_ from Redis (`INCR queue:length`). This signed JWT is sent back to the visitor as an HTTP cookie. - -On a regular basis, the current queue _cursor_ is updated in Redis (`INCR queue:cursor`). This effectively lets a user in. To show a visitor how many others are in front of them in the queue, we subtract the current queue _cursor_ from the _position_ saved in their JWT. - -On subsequent requests, when a JWT is supplied, we verify the signature and extract the _position_ from the JWT. If the current queue _cursor_ is higher than the user's signed _position_, they will be allowed in. This model is similar to the way many real-world "take a ticket" queueing systems work, with the ticket dispenser offering the next available number, and a screen on the wall indicating which customer is "now being served". - - diff --git a/src/static/demo-thumb.png b/src/static/demo-thumb.png deleted file mode 100644 index 8368a48..0000000 Binary files a/src/static/demo-thumb.png and /dev/null differ