Giter Club home page Giter Club logo

Comments (4)

clydin avatar clydin commented on May 10, 2024

Are you using the proxy option to alter the requests or are you using a custom builder via programmatic usage of the development server builder?

Would it be possible to provide an example of what you are attempting?

from angular-cli.

kamilchlebek avatar kamilchlebek commented on May 10, 2024

We're using custom builder to pass additional middleware.
At this moment excerpt from our middleware config looks like this:

themeAssets.map(
  (asset: string): NextHandleFunction =>
    function (req, res, next) {
      if (req.url?.includes(`/assets/${asset}`)) {
        const theme = parseThemeName(req)
        if (theme) {
          res.writeHead(302, {
            location: `/assets/context/${theme}/${asset}`,
          })
          res.end()
          return
        }
      }
      next()
    },
)
  • themeAssets is an array of assets (logo.png, etc.),
  • parseThemeName extracts desired theme from the url.

We'd like to use the same approach for css files (for example, we want redirect theme-default.css to theme-XYZ.css when needed. Currently this is not possible, because custom middlewares are not executed for css files at all.

from angular-cli.

clydin avatar clydin commented on May 10, 2024

Ideally, this should be possible with a customized proxy configuration file. I'll see if I can put together an example.

Are you using the customized builder for anything beyond the additional middleware?

from angular-cli.

kamilchlebek avatar kamilchlebek commented on May 10, 2024

Ideally, this should be possible with a customized proxy configuration file.

It seems to work for images or other static assets, but doesn't for CSS files.

I've even tried to "catch-all" requests with:

export default {
  '/': {
    bypass: function (req, res, proxyOptions) {
      console.log(req.url)
    },
  },
}

When you visit localhost:4200/theme-default.css, only url containing favicon.ico is being logged.
When you visit localhost:4200/asset/header-logo.png, request is correctly intercepted and I can redirect it wherever I need.

Are you using the customized builder for anything beyond the additional middleware?

Yes, we also provide some esbuild plugins - mostly to replace some placeholders (using options.define).

from angular-cli.

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.