You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
May be a little convoluted but I was just trying to do something like this. This is what I came up with as a workaround for local dev and it seems to work. Basically, I just treated the root domain as a subdomain when developing locally.
I have some variables define that determine the domain I am targeting and will later use this in my middleware to filter where I want things to be routed.
The key here is making sure the root domain is treated as a subdomain root.localhost:3000 and the subdomain we are targeting is treated as the root localhost:3000.
Next, my middleware function uses the previously defined variables to determine our routes. I have the folders setup as the actual domain names for clarity here
exportfunctionmiddleware(req: NextRequest){const{ domain, path, key }=parse(req);// rewrite app to `/app.domain.com` folderif(APP_HOSTNAMES.has(domain)){returnNextResponse.rewrite(newURL(`/app.domain.com${path==="/" ? "" : path}`,req.url),);}// rewrite admin to `/admin.domain.com` folderif(ADMIN_HOSTNAMES.has(domain)){returnNextResponse.rewrite(newURL(`/admin.domain.com${path==="/" ? "" : path}`,req.url),);}// rewrite root to `/domain.com` folderif(ROOT_HOSTNAMES.has(domain)){returnNextResponse.rewrite(newURL(`/domain.com${path==="/" ? "" : path}`,req.url),);}// rewrite everything else to `/[domain]/[slug] dynamic routereturnNextResponse.rewrite(newURL(`/${domain}${path}`,req.url));}
Lastly, we can now go target the standard localhost:3000 and http://localhost:3000/api/auth/callback/google for our Google auth!
I have some variables define that determine the domain I am targeting and will later use this in my middleware to filter where I want things to be routed.
The key here is making sure the root domain is treated as a subdomain
root.localhost:3000
and the subdomain we are targeting is treated as the rootlocalhost:3000
.Next, my middleware function uses the previously defined variables to determine our routes. I have the folders setup as the actual domain names for clarity here
Lastly, we can now go target the standard
localhost:3000
andhttp://localhost:3000/api/auth/callback/google
for our Google auth!Originally posted by @CrutchTheClutch in #329 (comment)
The text was updated successfully, but these errors were encountered: