Skip to content

Commit 54e4ac8

Browse files
authored
feat: rename trafficMesh flag to edgeHandlers (#1906)
1 parent 9d6d3a3 commit 54e4ac8

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/commands/dev/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const FRAMEWORK_PORT_TIMEOUT = 6e5
136136

137137
const startProxyServer = async ({ flags, settings, site, log, exit, addonsUrls }) => {
138138
let url
139-
if (flags.trafficMesh) {
139+
if (flags.edgeHandlers || flags.trafficMesh) {
140140
url = await startForwardProxy({
141141
port: settings.port,
142142
frameworkPort: settings.frameworkPort,
@@ -223,6 +223,12 @@ class DevCommand extends Command {
223223
...flags,
224224
}
225225

226+
if (flags.trafficMesh) {
227+
warn(
228+
'--trafficMesh and -t are deprecated and will be removed in the near future. Please use --edgeHandlers or -e instead.',
229+
)
230+
}
231+
226232
await injectEnvVariables({ env: this.netlify.cachedConfig.env, log, site, warn })
227233

228234
const { addonsUrls, siteUrl, capabilities } = await getSiteInformation({
@@ -311,10 +317,15 @@ DevCommand.flags = {
311317
char: 'l',
312318
description: 'start a public live session',
313319
}),
320+
edgeHandlers: flagsLib.boolean({
321+
char: 'e',
322+
hidden: true,
323+
description: 'activates the Edge Handlers runtime',
324+
}),
314325
trafficMesh: flagsLib.boolean({
315326
char: 't',
316327
hidden: true,
317-
description: 'uses Traffic Mesh for proxying requests',
328+
description: '(DEPRECATED: use --edgeHandlers or -e instead) uses Traffic Mesh for proxying requests',
318329
}),
319330
locationDb: flagsLib.string({
320331
description: 'specify the path to a local GeoIP location database in MMDB format',

tests/command.dev.test.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const testMatrix = [
3232
{ args: [] },
3333

3434
// some tests are still failing with this enabled
35-
// { args: ['--trafficMesh'] }
35+
// { args: ['--edgeHandlers'] }
3636
]
3737

3838
const testName = (title, args) => (args.length <= 0 ? title : `${title} - ${args.join(' ')}`)
@@ -1210,7 +1210,61 @@ testMatrix.forEach(({ args }) => {
12101210
const version = Number.parseInt(process.version.slice(1).split('.')[0])
12111211
const EDGE_HANDLER_MIN_VERSION = 10
12121212
if (version >= EDGE_HANDLER_MIN_VERSION) {
1213-
test(testName('should serve edge handlers', args), async (t) => {
1213+
test(testName('should serve edge handlers with --edgeHandlers flag', args), async (t) => {
1214+
await withSiteBuilder('site-with-fully-qualified-redirect-rule', async (builder) => {
1215+
const publicDir = 'public'
1216+
builder
1217+
.withNetlifyToml({
1218+
config: {
1219+
build: { publish: publicDir },
1220+
redirects: [
1221+
{
1222+
from: '/edge-handler',
1223+
to: 'index.html',
1224+
status: 200,
1225+
edge_handler: 'smoke',
1226+
force: true,
1227+
},
1228+
],
1229+
},
1230+
})
1231+
.withContentFiles([
1232+
{
1233+
path: path.join(publicDir, 'index.html'),
1234+
content: '<html>index</html>',
1235+
},
1236+
])
1237+
.withEdgeHandlers({
1238+
fileName: 'smoke.js',
1239+
handlers: {
1240+
onRequest: (event) => {
1241+
event.replaceResponse(
1242+
// eslint-disable-next-line no-undef
1243+
new Response(null, {
1244+
headers: {
1245+
Location: 'https://google.com/',
1246+
},
1247+
status: 301,
1248+
}),
1249+
)
1250+
},
1251+
},
1252+
})
1253+
1254+
await builder.buildAsync()
1255+
1256+
await withDevServer({ cwd: builder.directory, args: [...args, '--edgeHandlers'] }, async (server) => {
1257+
const response = await got(`${server.url}/edge-handler`, {
1258+
followRedirect: false,
1259+
})
1260+
1261+
t.is(response.statusCode, 301)
1262+
t.is(response.headers.location, 'https://google.com/')
1263+
})
1264+
})
1265+
})
1266+
1267+
test(testName('should serve edge handlers with deprecated --trafficMesh flag', args), async (t) => {
12141268
await withSiteBuilder('site-with-fully-qualified-redirect-rule', async (builder) => {
12151269
const publicDir = 'public'
12161270
builder
@@ -1282,7 +1336,7 @@ testMatrix.forEach(({ args }) => {
12821336

12831337
await builder.buildAsync()
12841338

1285-
await withDevServer({ cwd: builder.directory, args: [...args, '--trafficMesh'] }, async (server) => {
1339+
await withDevServer({ cwd: builder.directory, args: [...args, '--edgeHandlers'] }, async (server) => {
12861340
const response = await got(`${server.url}/index.html`)
12871341

12881342
t.is(response.statusCode, 200)

0 commit comments

Comments
 (0)