Skip to content

Commit

Permalink
feat: Node 20 対応。リダイレクトでハングするのでリダイレクト先に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadashy committed Oct 21, 2023
1 parent b68fbe6 commit be63035
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
8 changes: 7 additions & 1 deletion src/feed/utils/feed-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export class FeedCrawler {
private rssParser;

constructor() {
this.rssParser = new RssParser();
this.rssParser = new RssParser({
maxRedirects: 5,
timeout: 1000 * 10,
headers: {
'user-agent': constants.requestUserAgent,
},
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/feed/utils/feed-storer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class FeedStorer {
allFeedItemHatenaCountMap: FeedItemHatenaCountMap,
storeDirPath: string,
): Promise<void> {
await fs.rmdir(storeDirPath, { recursive: true });
await fs.rm(storeDirPath, { recursive: true });
await fs.mkdir(storeDirPath, { recursive: true });

const blogFeeds: BlogFeed[] = [];
Expand Down
44 changes: 22 additions & 22 deletions src/resources/feed-info-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ARIGATOBANK', 'https://medium.com/feed/arigatobank-tech-blog'],
['Acroquest Technology', 'https://acro-engineer.hatenablog.com/feed'],
['Adways', 'https://blog.engineer.adways.net/feed'],
['Aiming', 'https://developer.aiming-inc.com/feed'],
['Aiming', 'https://developer.aiming-inc.com/feed/'],
['AppBrew', 'https://tech.appbrew.io/feed'],
['Assured', 'https://tech.assured.jp/feed'],
['BABYJOB', 'https://zenn.dev/p/babyjob/feed', [FLAG_ZENN_PUBLICATION]],
Expand All @@ -58,7 +58,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['CULTA', 'https://techblog.culta.jp/feed'],
['CastingONE', 'https://zenn.dev/p/castingone_dev/feed', [FLAG_ZENN_PUBLICATION]],
['CauchyE', 'https://zenn.dev/cauchye/feed'],
['Cerevo', 'https://tech-blog.cerevo.com/feed'],
['Cerevo', 'https://tech-blog.cerevo.com/feed/'],
['Chatwork', 'https://creators-note.chatwork.com/feed'],
['Classi', 'https://tech.classi.jp/feed'],
['Cluster', 'https://tech-blog.cluster.mu/rss'],
Expand All @@ -83,15 +83,15 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['Findy', 'https://findy-code.io/engineer-lab/rss'],
['Flatt Security', 'https://blog.flatt.tech/feed'],
['Fracton', 'https://tech.fracton.ventures/feed'],
['Fusic', 'https://tech.fusic.co.jp/feed'],
['Fusic', 'https://tech.fusic.co.jp/rss.xml'],
['G-gen', 'https://blog.g-gen.co.jp/feed'],
['GIBJapan', 'https://zenn.dev/p/gibjapan/feed', [FLAG_ZENN_PUBLICATION]],
['GMOアドパートナーズ', 'https://techblog.gmo-ap.jp/feed/'],
['GMOインターネット', 'https://developers.gmo.jp/feed/'],
['GMOグループ研究開発本部', 'https://recruit.gmo.jp/engineer/jisedai/blog/feed/'],
['GMOグローバルサイン・ホールディングス', 'https://tech.gmogshd.com/feed'],
['GMOグローバルサイン・ホールディングス', 'https://tech.gmogshd.com/feed/'],
['GMOペパボ', 'https://tech.pepabo.com/feed.xml'],
['GMOリサーチ', 'https://gmor-sys.com/feed'],
['GMOリサーチ', 'https://gmor-sys.com/feed/'],
['GREE', 'https://labs.gree.jp/blog/feed/'],
['GRIPHONE', 'https://tech.griphone.co.jp/feed/'],
['Game Server Services', 'https://gs2.hatenablog.com/feed'],
Expand Down Expand Up @@ -206,6 +206,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['Salesforce', 'https://developer.salesforce.com/jpblogs/feed/'],
['Sansan', 'https://buildersbox.corp-sansan.com/feed'],
['Seeed', 'https://lab.seeed.co.jp/feed'],
['STORES', 'https://product.st.inc/feed'],
['Seibii', 'https://zenn.dev/seibii/feed'],
['Showcase Gig', 'https://note.com/scg_tech/rss'],
['SmartBank', 'https://blog.smartbank.co.jp/feed'],
Expand All @@ -222,7 +223,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['TOWN', 'https://town.biz/tag/engineer/feed'],
['TURING', 'https://zenn.dev/p/turing_motors/feed', [FLAG_ZENN_PUBLICATION]],
['TURING', 'https://zenn.dev/turing/feed'],
['TVISION INSIGHTS', 'https://tech.tvisioninsights.co.jp/feed'],
['REVISIO', 'https://tech.revisio.co.jp/feed'],
['TVer Technologies', 'https://techblog.tver-tech.co.jp/feed'],
['TVer', 'https://techblog.tver.co.jp/feed'],
['TeamSpirit', 'https://teamspirit.hatenablog.com/feed'],
Expand All @@ -237,7 +238,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['Unipos', 'https://fringeneer.hatenablog.com/feed'],
['Uzabase', 'https://tech.uzabase.com/feed'],
['VA Linux', 'https://valinux.hatenablog.com/feed'],
['VirtualCast', 'https://virtualcast.jp/blog/category/tech/feed/'],
['VirtualCast', 'https://blog.virtualcast.jp/blog/category/tech/feed/'],
['Visional', 'https://engineering.visional.inc/blog/index.xml'],
['Voicy', 'https://medium.com/feed/voicy-engineering'],
['Voicy', 'https://zenn.dev/p/voicy/feed', [FLAG_ZENN_PUBLICATION]],
Expand All @@ -264,7 +265,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['dip', 'https://developer.dip-net.co.jp/feed'],
['divx', 'https://engineering.divx.co.jp/feed'],
['efoo', 'https://efoo.hatenablog.com/feed'],
['estie', 'https://inside.estie.co.jp/feed'],
['estie', 'https://www.estie.jp/blog/feed'],
['for Startups', 'https://tech.forstartups.com/feed'],
['freee', 'https://developers.freee.co.jp/feed'],
['gaudiy', 'https://techblog.gaudiy.com/feed'],
Expand Down Expand Up @@ -297,7 +298,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['おてつたび', 'https://zenn.dev/otetsutabi_tech/feed'],
['くらしのマーケット', 'https://tech.curama.jp/feed'],
['ぐるなび', 'https://developers.gnavi.co.jp/feed'],
['さくら', 'https://knowledge.sakura.ad.jp/rss/'],
['さくら', 'https://knowledge.sakura.ad.jp/feed/'],
['じげん', 'https://overs.zigexn.co.jp/technology/feed/'],
['ちょっと', 'https://zenn.dev/p/chot/feed', [FLAG_ZENN_PUBLICATION]],
['はてな', 'https://developer.hatenastaff.com/feed'],
Expand All @@ -317,7 +318,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['アットホーム', 'https://dblog.athome.co.jp/feed'],
['アトラエ', 'https://atraetech.hatenablog.com/feed'],
['アプトポッド', 'https://tech.aptpod.co.jp/feed'],
['アプリボット', 'https://blog.applibot.co.jp/feed'],
['アプリボット', 'https://blog.applibot.co.jp/feed/'],
['アメリエフ', 'https://staffblog.amelieff.jp/feed'],
['アルサーガパートナーズ', 'https://zenn.dev/p/arsaga/feed', [FLAG_ZENN_PUBLICATION]],
['アルダグラム', 'https://zenn.dev/aldagram/feed'],
Expand All @@ -332,7 +333,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ウィルゲート', 'https://tech.willgate.co.jp/feed'],
['ウイングアーク1st', 'https://note.wingarc.com/m/m1d39b8a5d9be/rss'],
['ウェイブ', 'https://zenn.dev/p/wwwave/feed', [FLAG_ZENN_PUBLICATION]],
['ウエディングパーク', 'https://engineers.weddingpark.co.jp/feed'],
['ウエディングパーク', 'https://engineers.weddingpark.co.jp/feed/'],
['ウォーターセル', 'https://watercelldev.hatenablog.jp/feed'],
['エキサイト', 'https://tech.excite.co.jp/feed'],
['エクサウィザーズ', 'https://techblog.exawizards.com/feed'],
Expand All @@ -344,7 +345,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['エムスリー', 'https://www.m3tech.blog/feed'],
['エムティーアイ', 'https://tech.mti.co.jp/feed'],
['エーピーコミュニケーションズ', 'https://techblog.ap-com.co.jp/feed'],
['オイシックス', 'https://creators.oisix.co.jp/feed'],
['オイシックス・ラ・大地', 'https://creators.oisixradaichi.co.jp/feed'],
['オプトテクノロジーズ', 'https://tech-magazine.opt.ne.jp/feed'],
['オルターブース', 'https://aadojo.alterbooth.com/feed'],
['オールアバウト', 'https://allabout-tech.hatenablog.com/feed'],
Expand Down Expand Up @@ -389,7 +390,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['サムザップ', 'https://tech.sumzap.co.jp/feed'],
['シェアフル', 'https://zenn.dev/sharefull/feed'],
['シタテル', 'https://tech-blog.sitateru.com/feeds/posts/default'],
['シナジーマーケティング', 'https://techscore.hatenablog.com/feed'],
['シナジーマーケティング', 'https://blog.techscore.com/feed'],
['シナプス', 'https://tech.synapse.jp/feed'],
['シビラ', 'https://zenn.dev/sivira/feed'],
['シンシア', 'https://xincere-tech.hatenablog.com/feed'],
Expand Down Expand Up @@ -419,7 +420,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ダイアログ', 'https://dialog-tech.hatenablog.com/feed'],
['ダイニー', 'https://note.com/dinii/m/mf6424286cfa2/rss'],
['ダンクハーツ', 'https://dhe.dank-hearts.net/m/m18705e344ee6/rss'],
['テクニカルエージェント', 'https://tracl.cloud/archives/engineerblog/feed/'],
['テクニカルエージェント', 'https://tracl.cloud/archives/engineerblog/feed'],
['テコテック', 'https://tec.tecotec.co.jp/feed'],
['テックタッチ', 'https://tech.techtouch.jp/feed'],
['テックファーム', 'https://www.techfirm.co.jp/blog/?feed=rss2'],
Expand All @@ -441,7 +442,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ドリコム', 'https://tech.drecom.co.jp/feed/'],
['ドワンゴ', 'https://dwango.github.io/index.xml'],
['ドワンゴ教育サービス', 'https://blog.nnn.dev/feed'],
['ナレッジコミュニケーション', 'https://recipe.kc-cloud.jp/feed'],
['ナレッジコミュニケーション', 'https://recipe.kc-cloud.jp/feed/'],
['ナレッジワーク', 'https://note.com/knowledgework/rss'],
['ナンバーフォー', 'https://zenn.dev/p/no4_dev/feed', [FLAG_ZENN_PUBLICATION]],
['ニフクラ', 'https://blog.pfs.nifcloud.com/feed'],
Expand All @@ -454,7 +455,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ハウテレビジョン', 'https://blog.howtelevision.co.jp/feed'],
['ハコベル', 'https://zenn.dev/p/hacobell_dev/feed', [FLAG_ZENN_PUBLICATION]],
['ハロー', 'https://tech.hello.ai/feed'],
['ハンズラボ', 'https://www.hands-lab.com/feed'],
['ハンズラボ', 'https://www.hands-lab.com/feed/'],
['ハートビーツ', 'https://heartbeats.jp/hbblog/atom.xml'],
['バイセル', 'https://tech.buysell-technologies.com/feed'],
['バスキュール', 'https://blog.bascule.co.jp/feed'],
Expand All @@ -463,7 +464,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['パーソルキャリア', 'https://techtekt.persol-career.co.jp/feed'],
['パーソルプロセス&テクノロジー', 'https://note.com/ppt_hr/m/md77242321979/rss'],
['パーソンリンク', 'https://zenn.dev/person_link/feed'],
['ヒストリア', 'https://historia.co.jp/feed'],
['ヒストリア', 'https://historia.co.jp/feed/'],
['ヒュープロ', 'https://hupro-techblog.hatenablog.com/feed'],
['ビザスク', 'https://tech.visasq.com/feed'],
['ビザスク', 'https://zenn.dev/p/visasq/feed', [FLAG_ZENN_PUBLICATION]],
Expand All @@ -480,14 +481,13 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['フォージビジョン', 'https://techblog.forgevision.com/feed'],
['フューチャー', 'https://future-architect.github.io/atom.xml'],
['フリュー', 'https://tech.furyu.jp/feed'],
['フリークアウト', 'https://backyard.fout.co.jp/feed'],
['フリークアウト', 'https://backyard.fout.co.jp/feed/'],
['ブックウォーカー', 'https://developers.bookwalker.jp/feed'],
['ブレインズコンサルティング', 'https://blog.brains-consulting.tech/feed'],
['プラチナゲームズ', 'https://www.platinumgames.co.jp/official-blog/feed/'],
['プラハ', 'https://zenn.dev/p/praha/feed', [FLAG_ZENN_PUBLICATION]],
['プラミナス', 'https://zenn.dev/plminus/feed'],
['プレックス', 'https://product.plex.co.jp/feed'],
['ヘイ', 'https://tech.hey.jp/feed'],
['ベイジ', 'https://baigie.me/feed/'],
['ベルシステム', 'https://note.com/pocke_techblog/rss'],
['ペイトナー', 'https://paytner.hatenablog.com/feed'],
Expand Down Expand Up @@ -523,7 +523,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['モンスターラボ', 'https://engineering.monstar-lab.com/rss/feed_jp.xml'],
['ユカシカド', 'https://note.com/tech_yukashikado/rss'],
['ユニファ', 'https://tech.unifa-e.com/feed'],
['ユニラボ', 'https://note.unilabo.jp/m/mc84cf9468445/rss'],
['ユニラボ', 'https://note.proni.co.jp/m/mc84cf9468445/rss'],
['ユビレジ', 'https://note.com/ubiregi/m/madc9f4f38ad9/rss'],
['ライトハウス', 'https://developers.lighthouse-frontier.tech/feed'],
['ラクス', 'https://tech-blog.rakus.co.jp/feed'],
Expand All @@ -534,7 +534,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['ランサーズ', 'https://engineer.blog.lancers.jp/feed/'],
['リクルートコミュニケーションズ', 'https://blog.recruit.co.jp/rco/feed.xml'],
['リクルートテクノロジーズ', 'https://blog.recruit.co.jp/rtc/feed/'],
['リクルートマーケティングパートナーズ', 'https://tech.recruit-mp.co.jp/feed/'],
['リクルートマーケティングパートナーズ', 'https://blog.recruit.co.jp/rmp/feed/'],
['リクルートライフスタイル', 'https://engineer.recruit-lifestyle.co.jp/techblog/feed.xml'],
['リサーチ・アンド・イノベーション', 'https://rni-dev.hatenablog.com/feed'],
['リゾーム', 'https://tech.rhizome-e.com/feed'],
Expand Down Expand Up @@ -563,7 +563,7 @@ export const FEED_INFO_LIST: FeedInfo[] = createFeedInfoList([
['弁護士ドットコム', 'https://creators.bengo4.com/feed'],
['弥生', 'https://tech-blog.yayoi-kk.co.jp/feed'],
['日本仮想化技術', 'https://tech.virtualtech.jp/feed'],
['日販テクシード', 'https://www.techceed-inc.com/engineer_blog/feed/'],
['日販テクシード', 'https://techceed-inc.com/engineer_blog/feed/'],
['朝日ネット', 'https://techblog.asahi-net.co.jp/feed'],
['朝日新聞社', 'https://note.com/asahi_ictrad/rss'],
['楽天コマース', encodeURI('https://commerce-engineer.rakuten.careers/feed/category/テック')],
Expand Down
30 changes: 28 additions & 2 deletions tests/feed-info-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { FEED_INFO_LIST, FeedInfo } from '../src/resources/feed-info-list';
import { FeedCrawler } from '../src/feed/utils/feed-crawler';
import { describe, it, expect } from 'vitest';
import { backoff } from '../src/feed/utils/common-util';
const RssParser = require('rss-parser');
import RssParser from 'rss-parser';
import { to } from 'await-to-js';

const rssParser = new RssParser();
const rssParser = new RssParser({
maxRedirects: 0,
});

// 設定のテスト
describe('FEED_INFO_LIST', () => {
Expand All @@ -31,3 +34,26 @@ describe('フィードが取得可能', () => {
);
});
});

// リダイレクトされないテスト
// rss-parser がリダイレクトするURLだとハングするため
describe('リダイレクトされない', () => {
FEED_INFO_LIST.map((feedInfo: FeedInfo) => {
const testTitle = `${feedInfo.label} / ${feedInfo.url}`;
it.concurrent(
testTitle,
async () => {
const [error, response] = await to(fetch(feedInfo.url, { redirect: 'manual' }));
// リダイレクトしていないことを確認
expect(error).toBeNull();
expect(response).not.toBeNull();
if (response) {
const rerirectTo = response.headers.get('location');
expect(response.status, `Redirected to: ${rerirectTo}`).not.toEqual(301);
expect(response.status, `Redirected to: ${rerirectTo}`).not.toEqual(302);
}
},
180 * 1000,
);
});
});

0 comments on commit be63035

Please sign in to comment.