Comments (8)
I am currently working on Docusaurus for documenting the library; I need a couple of days before releasing more updated documentation.
About API pages, as for now, they're common to your tenants, so you should place your APIs inside of:
your-project/pages/api/
I'd like to know if there is more interest in having API routes divided by tenants as you were suggesting!
from krabs.
@sahanpd yeah that seems interesting! Let's open a discussion about that in https://github.com/micheleriva/krabs/discussions, I will close this ticket
from krabs.
@sahanpd @khromov FYI I've just released a new Krabs version where we spawn a warning when NODE_ENV variable is undefined: https://github.com/micheleriva/krabs/blob/main/src/index.ts#L18
thanks for you help!
from krabs.
Hey @khromov! Do you have some code/mocks to share?
from krabs.
Just checking in...did you add your domains to the host file as documented here?
That's usually the case for that 500 error...
from krabs.
Also (I need to update documentation for that), make sure to start the server with the correct NODE_ENV environment variable.
Given the following configuration:
module.exports = {
tenants: [
{
name: 'website-1',
domains: [
{
dev: /dev\.[a-z]*\.local\.website-1\.com/, // Regex supported!
stage: 'stage.website-1.com',
prod: 'website-1.com',
},
],
},
{
name: 'website-2',
domains: [
{
dev: 'local.website-2.com',
stage: 'stage.website-2.com',
prod: /[\w|\d|-|_]+\.website-2.com/, // Regex supported!
},
],
},
],
};
if you want to call any dev
, stage
, or prod
domain, you have to start your server with NODE_ENV=dev
, NODE_ENV=stage
, or NODE_ENV=prod
.
This is not clear in the documentation and is totally my fault. I'm gonna edit it to make that more clear, sorry!
from krabs.
@sahanpd @micheleriva NODE_ENV
, like this:
NODE_ENV=dev node server.js
I also have issues with my API routes and I don't see it documented how they should work. pages/the-standard/api/hello.js
.
The code is simply:
export default (req, res) => {
console.log(req);
res.status(200).json({ name: 'John Doe' })
}
When navigating to http://site.local:3000/api/hello
it doesn't work.
Instead of the req
object I get just { tenant: 'the-standard' }
and res
is just an empty object.
Is it possible to make standard Next.js API routes work?
Error:
TypeError: res.status is not a function
at __webpack_exports__.default (webpack-internal:///./pages/the-standard/api/hello.js:4:7)
at processChild (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
at resolve (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
at ReactDOMServerRenderer.render (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
at ReactDOMServerRenderer.read (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
at renderToString (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)
at Object.renderPage (/Users/stanislav.khromov/Documents/GitHub/next-multitenant/next-mt/node_modules/next/dist/next-server/server/render.js:54:854)
at Function.getInitialProps (webpack-internal:///./node_modules/next/dist/pages/_document.js:128:19)
...
from krabs.
Actually I'm currently working on adding an API end point to create tenant folders from a chosen template(I use an async config)...Ideally, I want to add it to my admin tenant.
So this could be a common enough usecase to consider, don't you think?
from krabs.
Related Issues (20)
- Fix GitHub CI workflow HOT 1
- Error trying to set up kraber HOT 3
- Tenant url does not work locally HOT 2
- Router push takes subdomain name? HOT 2
- How to add a CMS like Strapi HOT 1
- Guide of how to deloy this HOT 2
- NextJs's Link components do a full refresh HOT 4
- Next.js internationalized routing support
- public folder items not accessible HOT 1
- Slugs not working? HOT 1
- rewrites dont work HOT 4
- How to use Krabs in Production HOT 1
- Custom response for unlisted tenent HOT 1
- 'Common pages' functionality HOT 3
- Trying to add _middleware at pages directory doesn't work.
- API Routes HOT 1
- Example project does not work HOT 3
- problem start server.js
- How to tenants for subdomains or custom domain in the production?
- nextjs 12.3.0 - Error: Cannot find module 'colors' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from krabs.