kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
640 stars 22 forks source link

custom server (express) routes not resolved #114

Closed mogadanez closed 3 months ago

mogadanez commented 3 months ago

remix config:

import {flatRoutes} from "remix-flat-routes"

/** @type {import('@remix-run/dev').AppConfig} */
export default {
    ignoredRouteFiles: ["**/.*", "**/*.test.{js,jsx,ts,tsx}"],
    routes: async defineRoutes=>{
        return flatRoutes('routes', defineRoutes )
    },
    publicPath: "/_static/",
    server: "server.mjs",
    serverModuleFormat: "esm"
};
server taken from:
https://remix.run/docs/en/main/future/vite#migrating-a-custom-server

routes:

_auth+
  └── login.tsx

got Error: No route matches URL "/login"

if remove server: "server.mjs", from config works fine.

should I add something to server to support it?

kiliman commented 3 months ago

If you're using Vite, you need to move this config to vite.config.ts

export default defineConfig({
  plugins: [
    remix({
      ignoredRouteFiles: ["**/*"], // ignore everything from default convention
      routes: async defineRoutes=>{
          return flatRoutes('routes', defineRoutes, {
            ignoredRouteFiles: ["**/.*", "**/*.test.{js,jsx,ts,tsx}"]
          })
      },
      publicPath: "/_static/",
      server: "server.mjs",
      serverModuleFormat: "esm"
    }),
    tsconfigPaths(),
  ],
});