Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const FRAMEWORK_PORT_TIMEOUT = 6e5

const startProxyServer = async ({ flags, settings, site, log, exit, addonsUrls }) => {
let url
if (flags.trafficMesh) {
if (flags.edgeHandlers || flags.trafficMesh) {
url = await startForwardProxy({
port: settings.port,
frameworkPort: settings.frameworkPort,
Expand Down Expand Up @@ -223,6 +223,12 @@ class DevCommand extends Command {
...flags,
}

if (flags.trafficMesh) {
warn(
'--trafficMesh and -t are deprecated and will be removed in the near future. Please use --edgeHandlers or -e instead.',
)
}

await injectEnvVariables({ env: this.netlify.cachedConfig.env, log, site, warn })

const { addonsUrls, siteUrl, capabilities } = await getSiteInformation({
Expand Down Expand Up @@ -311,10 +317,15 @@ DevCommand.flags = {
char: 'l',
description: 'start a public live session',
}),
edgeHandlers: flagsLib.boolean({
char: 'e',
hidden: true,
description: 'activates the Edge Handlers runtime',
}),
trafficMesh: flagsLib.boolean({
char: 't',
hidden: true,
description: 'uses Traffic Mesh for proxying requests',
description: '(DEPRECATED: use --edgeHandlers or -e instead) uses Traffic Mesh for proxying requests',
}),
locationDb: flagsLib.string({
description: 'specify the path to a local GeoIP location database in MMDB format',
Expand Down
60 changes: 57 additions & 3 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const testMatrix = [
{ args: [] },

// some tests are still failing with this enabled
// { args: ['--trafficMesh'] }
// { args: ['--edgeHandlers'] }
]

const testName = (title, args) => (args.length <= 0 ? title : `${title} - ${args.join(' ')}`)
Expand Down Expand Up @@ -1210,7 +1210,61 @@ testMatrix.forEach(({ args }) => {
const version = Number.parseInt(process.version.slice(1).split('.')[0])
const EDGE_HANDLER_MIN_VERSION = 10
if (version >= EDGE_HANDLER_MIN_VERSION) {
test(testName('should serve edge handlers', args), async (t) => {
test(testName('should serve edge handlers with --edgeHandlers flag', args), async (t) => {
await withSiteBuilder('site-with-fully-qualified-redirect-rule', async (builder) => {
const publicDir = 'public'
builder
.withNetlifyToml({
config: {
build: { publish: publicDir },
redirects: [
{
from: '/edge-handler',
to: 'index.html',
status: 200,
edge_handler: 'smoke',
force: true,
},
],
},
})
.withContentFiles([
{
path: path.join(publicDir, 'index.html'),
content: '<html>index</html>',
},
])
.withEdgeHandlers({
fileName: 'smoke.js',
handlers: {
onRequest: (event) => {
event.replaceResponse(
// eslint-disable-next-line no-undef
new Response(null, {
headers: {
Location: 'https://google.com/',
},
status: 301,
}),
)
},
},
})

await builder.buildAsync()

await withDevServer({ cwd: builder.directory, args: [...args, '--edgeHandlers'] }, async (server) => {
const response = await got(`${server.url}/edge-handler`, {
followRedirect: false,
})

t.is(response.statusCode, 301)
t.is(response.headers.location, 'https://google.com/')
})
})
})

test(testName('should serve edge handlers with deprecated --trafficMesh flag', args), async (t) => {
await withSiteBuilder('site-with-fully-qualified-redirect-rule', async (builder) => {
const publicDir = 'public'
builder
Expand Down Expand Up @@ -1282,7 +1336,7 @@ testMatrix.forEach(({ args }) => {

await builder.buildAsync()

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

t.is(response.statusCode, 200)
Expand Down