Comments (2)
@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.
@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:
- I am trying to integrate Passport.js as discussed on this StackExchange question I posted
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)
- List re-rendering causes DOM state to be lost HOT 1
- Type definition for `createElement` is inaccurate
- Remove temporary support for v7 compiler + v6 engine
- Synthetic custom element lifecycle swallows DOM errors for `insertBefore` HOT 1
- Multiple Off-Platform LWC's on one page HOT 9
- array mutations are not reactive in a custom lightning-datatable component. HOT 2
- Add Karma fuzz-testing for mixed API version components HOT 1
- `disableSyntheticShadowSupport` should allow `<slot>`s to be static-optimized
- Remove `validationOptOut` for manual opt-outs of hydration mismatch validation HOT 1
- Upgrade to prettier v3
- Log warning for host mutation during SSR HOT 1
- Maintaining the Id Attributes after component render. HOT 2
- Remove remaining vestiges of `jest` types
- `lwc:spread` applies props rather than attributes
- Migrate from yarn to pnpm HOT 2
- Remove misleading warning when using `@wire` on a getter or a setter HOT 1
- Consider removing `setHooks`
- Light DOM slot forwarding fails to render for duplicated slot names HOT 1
- `@wire` on getter/setter ignores implementation
- Synthetic shadow + duplicate slots + slot forwarding: `Failed to execute 'removeChild' on 'Node'`
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 lwc.