Angular dev server got broken with the v18 upgrade

With the Angular 17.3 -> 18.0 upgrade, the local dev server (ng serve) got broken. We use it to connect the local dev instance to our backends in the cloud, for development. There were no config changes, only dependencies and unrelated code level migrations.

After the upgrade, some of the API requests were successful, but some returned 404, so working with the local dev server was not really possible any more. More specifically, some requests always worked, and some others always failed with 404, and it was seemingly random which ones. E.g. /api/v1/me and /api/v1/project?usedIn=false always worked, but some others like /api/v1/permissions/<username> always failed.

In our proxy-conf.json, we had to change the path wildcards from

{
  "/rest/v1/*": {
    "target": "https://company-fqdn.com:9080/app/api",
    "secure": false,
    "changeOrigin": true,
    "pathRewrite": {"^/rest" : ""}
  }
}

to "/rest/v1/**", note the double asterisks. Also, in hindsight, the requests that were successful only had a single path section after /rest/v1/ and the ones that did not were the ones that had multiple path sections, see my original examples.

Explanation and the steps I took to discover this:

  • ng serve --verbose outputs verbose info about what the dev proxy does
  • It said that the requests that were successful are being successfully proxied, but for the ones that returned 404 in the browser, the log said Not rewriting <method> <url> because the client prefers JSON
    • This was really confusing at first, because of course they were requesting json, because they are API calls.
    • But some research showed that this is the error message by some middleware library for the case when the usual SPA setup (always serve the index.html so that the client routing can kick in) receives a request with the Accept header specifying json, so the library can’t respond with the index.html
  • HHHa, that’s interesting, but still not that useful directly.
  • Started to look into what might be the library that does the parsing of the proxy config. Starting from https://angular.dev/tools/cli/serve#proxying-to-a-backend-server ended up looking at https://webpack.js.org/configuration/dev-server/#devserverproxy and some other stuff
  • … and somehow http-proxy-middleware also came up. Checked the docs of that, and multiple of the examples showed the ** syntax for a complete wildcard, instead of a single * which is rather just for a single part of the url. Changing this solved the issue.
  • Looked into the package-lock to check whether http-proxy-middleware was upgraded, as it is a transitive dependency, and indeed, it went from 2.0.6 to 3.0.0 … which may or may not be the direct cause of the issue.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật