Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting trailingSlash: true in the blitz configuration creates 308 redirects for all api requests. #286

Closed
cashmagnet opened this issue May 3, 2021 · 1 comment · Fixed by blitz-js/blitz#2392

Comments

@cashmagnet
Copy link

cashmagnet commented May 3, 2021

What is the problem?

API requests for blitz, from either await direct function calls inside useEffects or useQuery calls are not being created with consideration for the trailingSlash config.

What are detailed steps to reproduce this?

  1. create new blitz application
  2. update blitz.config.js as below
const { sessionMiddleware, simpleRolesIsAuthorized } = require("blitz")

module.exports = {
  middleware: [
    sessionMiddleware({
      isAuthorized: simpleRolesIsAuthorized,
    }),
  ],
  trailingSlash: true,

  /* Uncomment this to customize the webpack config
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    // Note: we provide webpack above so you should not `require` it
    // Perform customizations to webpack config
    // Important: return the modified config
    return config
  },
  */
}

  1. run your the blitz server (development or production, no difference)
  2. open up network tab in browser debugging tools
  3. navigate to the login screen - http://localhost:3000/login/
  4. you will see the getCurrentUser request is being requested without a trailing slash.

Run blitz -v and paste the output here:

Windows 10 | win32-x64 | Node: v12.18.2

blitz: 0.34.3 (global)
blitz: 0.34.3 (local)

  Package manager: yarn
  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
    Memory: 16.19 GB / 31.92 GB
  Binaries:
    Node: 12.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  npmPackages:
    @prisma/client: ~2.20 => 2.20.1
    blitz: 0.34.3 => 0.34.3
    prisma: ~2.20 => 2.20.1
    react: 0.0.0-experimental-6a589ad71 => 0.0.0-experimental-6a589ad71
    react-dom: 0.0.0-experimental-6a589ad71 => 0.0.0-experimental-6a589ad71
    typescript: ~4.2 => 4.2.4

Please include below any other applicable logs and screenshots that show your problem:

No response

@flybayer
Copy link
Member

flybayer commented May 4, 2021

To Fix

  1. Add trailingSlash to the blitz runtime data: https://github.com/blitz-js/blitz/blob/canary/packages/core/src/blitz-data.tsx#L13
  2. Update getApiUrlFromResolverFilePath to add trailing slash if getBlitzRuntimeData().trailingSlash is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants