Skip to content

Commit

Permalink
fix: Dockerで動かした場合の環境変数を修正 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Jan 28, 2023
1 parent 20c0dd2 commit 66ccd15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ WORKDIR /app
COPY --from=builder /app/output .

ENV NODE_ENV=production
ENV CONFIG_FILE=/data/config.json
ENV TOKEN_FILE=/data/token.json
ENV CONFIG_PATH=/data/config.json
ENV NOTIFIED_PATH=/data/notified.json

COPY entrypoint.sh .
RUN chmod +x entrypoint.sh
Expand Down
17 changes: 10 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ const isConfig = (config: any): config is Configuration => {
return (
config &&
typeof config.discord === 'object' &&
// webhook_url がない場合は、token と channel_id がなければならない
// webhook_url があるか token と channel_id があるか
(config.discord.webhook_url ||
(config.discord.token && config.discord.channel_id)) &&
// token がある場合は、channel_id がなければならない
(!config.discord.token || config.discord.channel_id) &&
// token と channel_id がない場合は、webhook_url がなければならない
(!config.discord.token ||
!config.discord.channel_id ||
config.discord.webhook_url)
// webhook_url があるとき、string である
(config.discord.webhook_url === undefined ||
typeof config.discord.webhook_url === 'string') &&
// token があるとき、string である
(config.discord.token === undefined ||
typeof config.discord.token === 'string') &&
// channel_id があるとき、string である
(config.discord.channel_id === undefined ||
typeof config.discord.channel_id === 'string')
)
}

Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ function formatDate(dateRaw: string): string {
async function main() {
const config = loadConfig()

console.log('📡 Fetching campaigns...')
const campaigns = await getCampaigns()
const isFirst = Notified.isFirst()

const campaignInfos = campaigns.campaignObject[1].campaignList[0].campaignInfo
const newCampaigns = campaignInfos.filter((campaignInfo) => {
return !Notified.isNotified(campaignInfo.eventCode)
})
console.log(`📝 ${newCampaigns.length} new campaigns found.`)

for (const campaignInfo of newCampaigns) {
const {
Expand Down Expand Up @@ -61,5 +63,9 @@ async function main() {
}

;(async () => {
await main()
await main().catch((error) => {
console.error(error)
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1)
})
})()

0 comments on commit 66ccd15

Please sign in to comment.