node的rss-parse库在发送请求前会追加默认header,请求会返回404错误。经过测试,主要是因为Accept头导致此错误。
const DEFAULT_HEADERS = {
'User-Agent': 'rss-parser',
'Accept': 'application/rss+xml',
}
修复后的代码如下:
FeedPluginEndpoint.java
@Bean
RouterFunction<ServerResponse> sitemapRouterFunction() {
return RouterFunctions.route(GET("/feed.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
feedService::allFeed)
.andRoute(GET("/rss.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
feedService::allFeed)
.andRoute(GET("/feed/categories/{category}.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
request -> feedService.categoryFeed(request, request.pathVariable("category")))
.andRoute(GET("/feed/authors/{author}.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
request -> feedService.authorFeed(request, request.pathVariable("author")));
}
node的rss-parse库在发送请求前会追加默认header,请求会返回404错误。经过测试,主要是因为Accept头导致此错误。
修复后的代码如下:
FeedPluginEndpoint.java