pwa-kit icon indicating copy to clipboard operation
pwa-kit copied to clipboard

[FEATURE] Add an "echo" endpoint to the default app that responds with the details of the request

Open johnboxall opened this issue 1 year ago • 2 comments

CDNs often have quirks in terms of how they forward requests to origins.

When customers stack a CDN on MRT, we often debug request forwarding issues To debug issues with forwarding, we often suggest customers add an "echo" endpoint to ssr.js to their apps:

// ssr.js
app.all('/reflect', function echoHandler({method, path, headers, body}, res) {
  return res.send({method, path, headers, body})
})

It would be nice if we included this endpoint by default in apps with an environment variable toggle so folks could enable it without a code change.

This would simplify debugging many of these issues!

johnboxall avatar Feb 14 '24 04:02 johnboxall

Hi @johnboxall 👋

Sounds like a good idea. I'm wondering is something like this might be a little more future-proof.

// ssr.js

import {devMiddleware} from `pwa-kit-react-sdk`

...

if (!env.isProduction || env.enableServerDevEnpoint) {
    app.use(devMiddleware())
}

Here we can add your suggested reflect endpoint under a common /__dev path. This would allow use to add more end-points with out worrying about coming up with pathnams that might collide with user defined ones. Another idea might be /__dev/info that would give the user and us details about the version of sdk/node/etc they are using.

bendvc avatar Feb 16 '24 17:02 bendvc

@bendvc – your suggestion about not conflicting with existing customer routes is a good one!

Instead of introducing a new path, we could extend the current convention of /mobify/ping and friends with /mobify/reflect. Alternatively, we could even extend ping to conditionally provide this information.

One key part of my suggestion is that ideally this endpoint is available across all environments (including production ones!) and can be enabled without a code change – so I'm imagining something that is default off, but can be enabled using an MRT environment variable (eg. MRT_REFLECT_ENABLED=$TRUTHY)

johnboxall avatar Feb 16 '24 19:02 johnboxall