Skip to content

Commit

Permalink
[CJS-8565] local/dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jlombana-opti committed Nov 14, 2024
1 parent b723b07 commit 48f4c08
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ dist
.wrangler/

.DS_Store
/.idea
1 change: 1 addition & 0 deletions templates/edge-delivery-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"dev:env": "wrangler dev --env=dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types"
},
Expand Down
16 changes: 11 additions & 5 deletions templates/edge-delivery-starter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import { applyExperiments } from '@optimizely/edge-delivery';

interface Env {
SNIPPET_ID: string;
DEV_URL: string;
isDev: boolean;
host: string;
upstream_protocol?: string;
upstream_pathname?: string;
}

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return await handleRequest(request, env, ctx);
Expand All @@ -27,13 +30,16 @@ export default {
async function handleRequest(request: Request, env: Env, ctx: ExecutionContext) {
// Configure all the options to pass to Optimizely
const options = {
isDev: env.isDev,
"snippetId": env.SNIPPET_ID,
"devUrl": env.DEV_URL,
host: env.host,
upstream_protocol: env.upstream_protocol,
upstream_pathname: env.upstream_pathname,
};

// Make experiment decisions based on the request information
// Apply those changes to the control
// Any decisions or changes that cannot be made here are packaged together
// and added to the <head> element for execution on the browser
// Any decisions or changes that cannot be made here are packaged together
// and added to the <head> element for execution on the browser
return await applyExperiments(request, ctx, options);
}
9 changes: 8 additions & 1 deletion templates/edge-delivery-starter/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ compatibility_flags = ["nodejs_compat"]

[vars]
SNIPPET_ID = "29061560280"
DEV_URL = "https://example.com/"
host = 'example.com'

[env.dev.vars]
SNIPPET_ID = "29061560280"
isDev = true
host = "optimizely.github.io"
upstream_protocol = 'https'
upstream_pathname = 'jlombana'

0 comments on commit 48f4c08

Please sign in to comment.