How to handle errors when a basePath
is specified and requests are made outside it?
#112
-
Hello, I specify a However, any request made outside that path (e.g. Is there a good way to handle these requests? Or is this something I should handle further up the stack (e.g. in my nginx configuration)? I already have both a (I'm on remix 2.8.1 (not using Vite), Node 20, remix-flat-routes 0.6.4) Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The way basePath works is that it just generates routes with that prefix added, so Remix isn't doing anything special. When it sees Even though you have a However, you can manually define the splat route in your config file. const { flatRoutes } = require('remix-flat-routes')
/**
* @type {import("@remix-run/dev").AppConfig}
*/
module.exports = {
// ignore all files in routes folder to prevent
// default remix convention from picking up routes
routes: async defineRoutes => {
let routes = flatRoutes('routes', defineRoutes, {
ignoredRouteFiles: ['**/*.test.{js,jsx,ts,tsx}', '**/__*.*'],
basePath: '/bff',
})
let splatRoute = defineRoutes(route => route('*', 'routes/$.tsx'))
return { ...routes, ...splatRoute }
},
} I would recommend that you migrate to Vite when you can as it now supports the |
Beta Was this translation helpful? Give feedback.
The way basePath works is that it just generates routes with that prefix added, so Remix isn't doing anything special. When it sees
/foo
, it looks to see if there's a route and, if not, throws a not found response.Even though you have a
route/$.tsx
file,remix-flat-routes
is treating it like you had abff/$.tsx
route, so that's why it's not catching the invalid routes. Also, the root route is only called if Remix finds a valid route to begin with.However, you can manually define the splat route in your config file.