Giter Site home page Giter Site logo

Comments (3)

CWSpear avatar CWSpear commented on May 3, 2024

A few more things I looked into:

Express allows Regular Expressions for their routes. So even tho renderPath is typed as a string for AngularUniversalOptions, if I pass in a RegEx, is will register with Express. This could mean we don't need an explicit white/blacklist. However...

I tried passing in /^\/(?!members).*/--basically all routes except those that start with /members--and that did indeed make it so it only rendered non member routes with SSR... but then it would result in a 404 for /members paths.

There needs to be a fallback that will return templatePath's contents when the renderPath is not matched.

As a workaround for now, I put this high up in my server's main.ts:

export async function bootstrap(): Promise<NestExpressApplication> {
  const expressApp: Express = express();

  expressApp.use(compression());
 
  // this allows us to skip over SSR for members area
  expressApp.get(/^\/members/, (req: Request, res: Response) => {
    const path = join(__dirname, '../client/index.html');
    res.sendFile(path);
  });

  // other code and setting up Nest...
}

It would probably work as a catchall if I registered it last, too with app.get('*', ...) if I combined it with the RegEx renderPath I mentioned above.

It seems like this is something that could be built into this module, maybe?

from ng-universal.

fullofcaffeine avatar fullofcaffeine commented on May 3, 2024

It'd be nice to have selective SSR indeed. Is it something that's planned? At the moment, I have this in my app, but I implemented it myself with React, but I'm considering Angular/Nest for another app.

from ng-universal.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

We don't plan to add more features to this feature as it is supposed to be a tiny wrapper on top of @nguniversal/express-engine. If anyone needs more functionalities, we recommend forking this package and bringing it to the project's codebase.

from ng-universal.

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.