madhusudanbabar / k-domains Goto Github PK
View Code? Open in Web Editor NEWA simple module to manage multiple subdomains with just one project
Home Page: https://www.npmjs.com/package/k-domains
License: MIT License
A simple module to manage multiple subdomains with just one project
Home Page: https://www.npmjs.com/package/k-domains
License: MIT License
First of all, nice work done with this package.
Now, imagine this use case:
bestshoes.myplatform.com
or foodsite.myplatform.com
. And for sure we'd need to be able to get the current subdomain to use it as a param form API requests, so we can get the right data for each store.Is it possible right now? Or is it even viable with some work in this module code?
I tried using k-modules for my project, followed the full instructions and had the following problem. I hope everyone will help me
It would be very nice if there was an optional flag disabling the check:
if the subdomain is not in the list of user provided domains, set the rootdirectory to root - domain given by the user
This way, when a subdomain does not exist, it would be redirected to the 404 page.
Version:
1.2.5
Config:
buildModules: [
[ 'k-domains', { subDomains: [ 'api' ], rootDomain: 'root' } ],
[ '@nuxtjs/router', { keepDefaultRouter: true } ]
]
Layout:
/pages
/api
index.vue
api.pug
api.styl
api.ts
/root
index.vue
/login
index.vue
login.pug
login.styl
login.ts
/index
index.pug
index.styl
index.ts
Error:
ERROR Cannot read property 'substr' of undefined
at server.js:1965:28
at Array.map (<anonymous>)
at createRouter (src/router.js:57:0)
at router_createRouter (src/.nuxt/router.js:6:0)
at createApp (src/.nuxt/index.js:69:0)
at module.exports.__webpack_exports__.default (src/.nuxt/server.js:82:0)
at node_modules/vue-server-renderer/build.prod.js:1:78608
at new Promise (<anonymous>)
at node_modules/vue-server-renderer/build.prod.js:1:78080
at Object.renderToString (node_modules/vue-server-renderer/build.prod.js:1:81615)
I attached a console.log to route.path and route.name (line 57 on router.js) and this is what the output was:
/api
api
/api/api
api-api
/root
undefined
/root/login
root-login
/root/login/login
root-login-login
Possible Solution:
(I made this change manually to my setup and it made it work)
change this:
return {
...route,
path: route.path.substr(routesDirectory.length + 1) || "/",
name: route.name.substr(routesDirectory.length + 1) || "index"
}
to this: (add optional chaining)
return {
...route,
path: route.path?.substr(routesDirectory.length + 1) || "/",
name: route.name?.substr(routesDirectory.length + 1) || "index"
}
After following the tutorial (npm i k-domains @nuxtjs/router), and applying the change to the nuxt config file and the pages directory, every page gives this error multiple times:
ERROR in ./node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs friendly-errors 17:20:48
Can't reexport the named export 'watchEffect' from non EcmaScript module (only default export is available) friendly-errors 17:20:48
friendly-errors 17:20:48
ERROR in ./node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs friendly-errors 17:20:48
Can't reexport the named export 'watchPostEffect' from non EcmaScript module (only default export is available) friendly-errors 17:20:48
friendly-errors 17:20:48
ERROR in ./node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs friendly-errors 17:20:48
Can't reexport the named export 'watchSyncEffect' from non EcmaScript module (only default export is available)
Hello, how can I go to a subdomain using a nuxt-link without knowing whether I am on a localhost or on a server?More precisely, how can I switch from a domain to a subdomain what write - go to sub
Currently, k-domains redirects to the root domain if the domain specified is not found.
// if the subdomain is not in the list of user provided domains, set the rootdirectory to root - domain given by the user
Would it be possible to add an option to change this behaviour to just redirect to the error 404 page?
Ps. Thanks for leaving in at least some comments, I don't understand why large scale projects never have those. It made it lots easier for me to understand.
Hello, how can I make k-domains work with nuxt-18n? I tried and the switchLocalePath seems to be broken and on compile some warnings were thrown
WARN [vue-router] Route with name '__id___id' does not exist
WARN [vue-router] Route with name 'index___id' does not exist
WARN [vue-router] Route with name '__id___en' does not exist
WARN [vue-router] Route with name '__id___id' does not exist
Use this.options.extendRoutes
in module directly, and so there is no need to have @nuxtjs/router
dependency
Hi there,
here's my nuxt.config buildModules section:
buildModules: [
[
'k-domains',
{
subDomains: ['app'],
rootDomain: 'root',
},
],
[
'@nuxtjs/router',
{
keepDefaultRouter: true, // this line is mandatory...
},
],
],
and so I expect app.myDomain/
to render the index.vue inside my pages/app
directory
similarly, I expect myDomain/
to render the index.vue inside my pages/root
directory
Instead I get a This page could not be found
nuxt error:
Am I missing something?
thanks!
Hi, do you think it's possible to have a sub-domain be a SPA and the root-domain be Static?
your blog subdomain still can access the root domain
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.