Skip to content

Commit 69e53bf

Browse files
committed
Update build script
1 parent 5f7cb93 commit 69e53bf

File tree

6 files changed

+25
-61
lines changed

6 files changed

+25
-61
lines changed

Diff for: examples/v7-optimizely-edge/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ git clone ...
2525
npm install
2626
```
2727

28-
3. Create a `.env.local` file in the root of the project and add the following environment variables:
28+
3. Create a `.env` file in the root of the project and add the following environment variables:
2929

3030
```bash
3131
OPTIMIZELY_SDK_KEY=...

Diff for: examples/v7-optimizely-edge/edge-functions/main.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const COOKIE_NAME = 'optimizely_visitor_id';
1818
* @returns {Response} The HTTP response after applying A/B testing logic.
1919
*/
2020
export async function handleHttpRequest(request, context) {
21-
console.log(JSON.stringify(request.headers, null, 2)); // Log request headers for debugging
22-
2321
// Retrieve or generate a unique user ID from cookies
2422
const userId =
2523
request.headers
@@ -28,7 +26,8 @@ export async function handleHttpRequest(request, context) {
2826
.find((cookie) => cookie.trim().startsWith(`${COOKIE_NAME}=`))
2927
?.split('=')[1] || uuidv4();
3028

31-
// Create an Optimizely instance with the preloaded datafile and configuration
29+
// Create an Optimizely instance with the preloaded datafile and configuration.
30+
// This edge function uses the Optimizely SDK Lite which requires a preloaded datafile.
3231
const instance = createInstance({
3332
datafile: optimizelyDatafile,
3433
clientEngine: CLIENT_ENGINE,

Diff for: examples/v7-optimizely-edge/edgio.config.js

-41
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// You should commit this file to source control.
33
// Learn more about this file at https://docs.edg.io/guides/edgio_config
44
module.exports = {
5-
//connector: '@edgio/next',
6-
75
// The name of the site in Edgio to which this app should be deployed.
86
// name: 'my-site-name',
97

@@ -17,45 +15,6 @@ module.exports = {
1715
// effectively purging the cache each time you deploy.
1816
// purgeCacheOnDeploy: false,
1917

20-
next: {
21-
// Output sourcemaps so that stack traces have original source filenames and line numbers when tailing
22-
// the logs in the Edgio developer console.
23-
// This config options replaces the edgioSourceMaps option in next.config.js.
24-
// @default true
25-
// generateSourceMaps: true
26-
//
27-
// Disables the Edgio image optimizer and allows to use the Next's built in image optimizer.
28-
// This config options replaces the disableImageOptimizer option in edgio.config.js root.
29-
// @default false
30-
// disableImageOptimizer: false
31-
//
32-
// Disables the build of the service worker.
33-
// @default false
34-
// disableServiceWorker: false
35-
//
36-
// Forces the @edgio/next connector to use the server build.
37-
// This config option replaces the NEXT_FORCE_SERVER_BUILD env variable.
38-
// @default false
39-
// forceServerBuild: false
40-
//
41-
// Optimizes the server build by bundling all server assets and decreasing the overall startup time.
42-
// This option has no effect on apps with serverless build.
43-
// This option is set to false for Next 13.x apps.
44-
// @default true
45-
// optimizeServerBuild: true
46-
//
47-
// Set this option to false to remove the default rule that proxies all requests to Next.js in serverless.
48-
// This is useful if you want to proxy all unmatched pages to different origin.
49-
// @default true
50-
// proxyToServerlessByDefault: true
51-
//
52-
// Set this option to true to honor Next's internal redirects that either add or remove a trailing slash
53-
// depending on the value of the `trailingSlash` config. When set to false, these internal redirects are not honored,
54-
// so sites that fallback to serving from an origin do not add or remove the trailing slash for origin URLs.
55-
// @default true
56-
// enforceTrailingSlash: true
57-
},
58-
5918
// If you need to proxy some URLs to an origin instead of your Next.js app, you can configure the origins here:
6019
origins: [
6120
{

Diff for: examples/v7-optimizely-edge/package-lock.json

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

Diff for: examples/v7-optimizely-edge/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"scripts": {
33
"edgio:dev": "edgio dev",
4-
"edgio:build": "edgio build",
5-
"edgio:deploy": "edgio deploy",
4+
"edgio:build": "node scripts/fetch_optimizely_datafile.js && edgio build",
5+
"edgio:deploy": "npm run edgio:build && edgio deploy --skip-build",
66
"start": "edgio dev"
77
},
88
"name": "edgio-v7-optimizely-edge-example",
@@ -16,7 +16,8 @@
1616
"@edgio/devtools": "^7.11.4",
1717
"@edgio/next": "^7.11.4",
1818
"@edgio/prefetch": "^7.11.4",
19-
"@edgio/react": "^7.11.4"
19+
"@edgio/react": "^7.11.4",
20+
"dotenv": "^16.4.5"
2021
},
2122
"repository": "[email protected]:edgio-docs/edgio-v7-optimizely-edge-example.git",
2223
"dependencies": {

Diff for: examples/v7-optimizely-edge/scripts/fetch_optimizely_datafile.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const fetch = require('node-fetch');
3+
require('dotenv').config();
34

45
const DATAFILE_DIR = './lib/optimizely';
56

@@ -26,15 +27,6 @@ async function fetchDatafile() {
2627
console.log(`Optimizely Datafile fetched successfully`);
2728
}
2829

29-
function withOptimizely(nextConfig = {}) {
30-
return {
31-
...nextConfig,
32-
// Not actually overwriting rewrites. Just using the async function to fetch optimizely datafile.
33-
rewrites: async () => {
34-
await fetchDatafile();
35-
return nextConfig.rewrites ? nextConfig.rewrites() : [];
36-
},
37-
};
38-
}
39-
40-
module.exports = withOptimizely;
30+
(async () => {
31+
await fetchDatafile();
32+
})();

0 commit comments

Comments
 (0)