Giter VIP home page Giter VIP logo

Comments (2)

khangiskhan avatar khangiskhan commented on August 9, 2024

@jeffolmstead can you detail your use case for using KOA over Express?

LWR handles Express/KOA routing internally, so adding your own external router is not an expected pattern and is unlikely to work (or be supported).

You can still add middleware that handles custom routes via:

// Express custom middleware example
const expressApp = lwrServer.getInternalServer<'express'>();
expressApp.use(async (req, res, next) => {
    const { path: requestPath } = req;
      if (requestPath === '/greetings') {
         // do something 
      } else {
         return next();
      }
});
// KOA custom middleware example
const koaApp = lwrServer.getInternalServer<'koa'>();

// Add koa middleware directly
koaApp.use(async (ctx, next) => {
      if (ctx.path === '/greetings') {
         // do something 
      } else {
         return next();
      }
});

from lwc.

jeffolmstead avatar jeffolmstead commented on August 9, 2024

@khangiskhan thanks for your reply and examples. As a background, I am working through trying to push the limits of LWR (while also trying to work within the approach it was designed for) prior to pushing into a specific use case for it. Using KOA over Express was purely to gain an understanding of the options presented by the LWR stack of exposing the internal server implementations.

Overarching Goals
The overarching goal of having the routes was to be able to test out the serving of REST API endpoints (or even GraphQL). I was able to do this with the "Express" server exposed, but the "KOA" didn't seem to be able to inject a new route. I will try your example above.

I also realize I might need to switch my mentality down to the Web Component level with each maintaining it's own data access as opposed to a whole page mentality. In order to build working prototypes on LWR, I am trying to get the basics understood:

  • Authentication
  • Efficient data serving
  • Potential for API access

Basically boilerplate stuff to have a business solution, but how does it fit into LWR. Here is what I have encountered with authentication:

There are a lot of good examples for serving up LWR on node.js without authentication, and I have tapped into them. However, when trying to test out possibilities for having authenticated users (easy to do on Salesforce Experience sites), finding a working solution in an LWR server environment hasn't been easy. This is what led me to attempting to tap directly into the internal Express server.

TLDR
I am trying to figure out the extension points / best approach for integrating authentication and, if need be, API endpoints.

I will try out your example above and provide feedback after testing. If you have time to provide additional response, it is appreciated.

from lwc.

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.