-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Command
serve
Description
With the goal to move off the Webpack-based development server, we have a need to port some of the functionality currently supported by the @angular-builders/custom-webpack module.
In particular, we would like the ability to add custom middlewares to the dev server. In our case, this would be used to inject a connect-compatible middleware that acts as a means of providing authenticated access to proxied endpoints, by setting session cookies used for authorization.
Describe the solution you'd like
Vite's dev server currently supports proxy endpoints via an embedded http-proxy module, and provides documentation on customizing with additional middlewares:
In some cases, you might also want to configure the underlying dev server (e.g. to add custom middlewares to the internal connect app). In order to do that, you need to write your own plugin and use configureServer function.
The configureServer method exposes the custom middleware hook:
const myPlugin = () => ({
name: 'configure-server',
configureServer(server) {
server.middlewares.use((req, res, next) => {
// custom handle request...
})
},
})Describe alternatives you've considered
Exposing direct access to the Vite API may not align with the philosophy of the Angular CLI, but supporting the extensibility via custom builders would make these use cases feasible.
I see similar requests in other issues such as #24163 and just-jeb/angular-builders#1288
On a side note, I'm very excited to see CLI's build process move over to Vite; I've been using it outside Angular, and have given talks about how much I've enjoyed it: https://steele.blue/vite-is-neat/