Giter VIP home page Giter VIP logo

Comments (8)

micheleriva avatar micheleriva commented on May 25, 2024 1

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.

micheleriva avatar micheleriva commented on May 25, 2024 1

@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.

micheleriva avatar micheleriva commented on May 25, 2024 1

@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.

micheleriva avatar micheleriva commented on May 25, 2024

Hey @khromov! Do you have some code/mocks to share?

from krabs.

sahanpd avatar sahanpd commented on May 25, 2024

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.

micheleriva avatar micheleriva commented on May 25, 2024

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.

khromov avatar khromov commented on May 25, 2024

@sahanpd @micheleriva 🙇 Thanks so much for the help, the missing piece was starting with 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. 😢 I have a file in 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.

sahanpd avatar sahanpd commented on May 25, 2024

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)

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.