Giter Club home page Giter Club logo

Comments (12)

acorcutt avatar acorcutt commented on July 29, 2024

What do your rewrite rules look like?

Do you include the root...

{
  has: [
    {
      type: 'host',
      value: '(?<host>.*)',
    },
  ],
  source: '/',
  destination: '/hosts/:host',
},

from next-multi-host.

trankhacvy avatar trankhacvy commented on July 29, 2024

@acorcutt Thank you for your reply. What do you mean about include the root ?
This is my rule:

[
      {
        has: [
          {
            type: "host",
            value: "(?<host>.*)",
          },
        ],
        source: "/",
        destination: "/hosts/:host",
      },
      {
        has: [
          {
            type: "host",
            value: "(?<host>.*)",
          },
        ],
        source: "/:slug*",
        destination: "/hosts/:host/:slug*",
      },
    ]

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

I meant the root path '/' needs rewriting to avoid any default '/index.js' route but that looks ok.

This looks like it is related to #1 with the '/' and '/:slug*' routes both matching '/' try avoiding wildcards if possible or place them in sub-paths like '/pages/:slug*.'

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

I wonder if we can make the '/:slug*' not match the '/' route using a regex match maybe try something like source: "/:slug(.*)"

from next-multi-host.

trankhacvy avatar trankhacvy commented on July 29, 2024

@acorcutt still no luck. I put all rules inside the beforeFiles and when I access localhost:300, no response, just loading.

beforeFiles: [
      {
        has: [
          {
            type: "host",
            value: "(?<host>.*)",
          },
        ],
        source: "/",
        destination: "/hosts/:host",
      },
      {
        has: [
          {
            type: "host",
            value: "(?<host>.*)",
          },
        ],
        source: "/:slug(.*)",
        destination: "/hosts/:host/:slug*",
      },
    ]

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

Can you remove the index route and just use the slug route to catch it?

beforeFiles: [
      {
        has: [
          {
            type: "host",
            value: "(?<host>.*)",
          },
        ],
        source: "/:slug*",
        destination: "/hosts/:host/:slug*",
      },
    ]

Then check for context.params.slug == "" in '/hosts/:host/[[...slug]].js' for index?

In my example '/slugs/:slug*' matches both '/slugs' and '/slugs/a/b/c'

from next-multi-host.

trankhacvy avatar trankhacvy commented on July 29, 2024

@acorcutt I just update the rule to follow your suggestion but when I access localhost:3000, it's just loading. Look like an infinite loop. Out of memory occurs FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

This is working for me: https://stackblitz.com/edit/nextjs-s8pmir

I had to rename '[[...slug]].js' to '[...slug].js' and added 'index.js' as its own page.

from next-multi-host.

trankhacvy avatar trankhacvy commented on July 29, 2024

@acorcut sorry for unclear information. I mean the root index.js file in pages folder

Screen Shot 2021-10-17 at 20 48 13

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

Ok I see... this is going to conflict with your rewrites:

/index.tsx and source: "/" & source: "/:slug*" rewrites will all match '/', /dashboard.tsx would also match source: "/:slug(.*)"

You need to avoid any overlapping routes such as placing your slugs rewrite under its own path source: "/slugs/:slug*" if that is possible. You could try a regex to prevent it matching the other routes but I've had no luck with them. I don't think using beforeFiles or afterFiles helps in this situation.

I have a site with a similar structure to this and ended up splitting it into two separate apps so one app handles a single/host/[...slug] catch-all route and the other a dashboard which uses its own sub domain.

from next-multi-host.

trankhacvy avatar trankhacvy commented on July 29, 2024

@acorcutt very appreciate for your help. Ya, I think splitting into 2 apps is necessary.
once again, thank you.

from next-multi-host.

acorcutt avatar acorcutt commented on July 29, 2024

No problem, I'll close this and leave #1 open - not sure can fix with how the current routing and rewrites are ordered.

from next-multi-host.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.