Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Count Von Countdown](https://voncountdown.herokuapp.com/badge)](https://voncountdown.herokuapp.com)
[![Count Von Countdown](https://voncountdown.com/badge)](https://voncountdown.com)
[![Semver](https://img.shields.io/badge/SemVer-2.0-blue.svg)](http://semver.org/spec/v2.0.0.html)
[![license](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=2592000)](https://opensource.org/licenses/MIT)
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/)
Expand All @@ -24,7 +24,7 @@ A Twitter bot that counts down from a very large number, posting tweets with the

### Prerequisites

- Node.js 18+
- Node.js 20+
- AWS Account with DynamoDB access
- Twitter Developer Account with API v2 access

Expand Down Expand Up @@ -237,7 +237,7 @@ git push heroku main
### Docker

```dockerfile
FROM node:18-alpine
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
Expand Down
45 changes: 21 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,21 @@

//*******************************************************************

'use strict';

//*******************************************************************

const numberstring = require('numberstring');
const express = require('express');
const exphbs = require('express-handlebars');
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
const compression = require('compression');
const timeout = require('connect-timeout');
const axios = require('axios');
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocumentClient, ScanCommand, PutCommand } = require('@aws-sdk/lib-dynamodb');
const { TwitterApi } = require('twitter-api-v2');
const NodeCache = require('node-cache');

require('dotenv').config();
import numberstring, { comma } from 'numberstring';
import express from 'express';
import exphbs from 'express-handlebars';
import helmet from 'helmet';
import rateLimit from 'express-rate-limit';
import compression from 'compression';
import timeout from 'connect-timeout';
import axios from 'axios';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient, ScanCommand, PutCommand } from '@aws-sdk/lib-dynamodb';
import { TwitterApi } from 'twitter-api-v2';
import NodeCache from 'node-cache';
import dotenv from 'dotenv';

dotenv.config();

//*******************************************************************
// Simple Logger for App Runner/CloudWatch
Expand Down Expand Up @@ -267,7 +264,7 @@ let current_twext;
// Utility Functions
//*******************************************************************

const { randomInt } = require('./src/utils/random');
import { randomInt } from './src/utils/random.js';

//*******************************************************************
// Initialization
Expand Down Expand Up @@ -317,7 +314,7 @@ const { randomInt } = require('./src/utils/random');
});

current_number = CONFIG.APP.START_NUMBER;
current_comma = numberstring.comma(current_number);
current_comma = comma(current_number);
current_string = numberstring(current_number, { cap: 'title', punc: '!' });

logger.info('Generated initial state', {
Expand Down Expand Up @@ -360,7 +357,7 @@ const { randomInt } = require('./src/utils/random');
}

current_number = number;
current_comma = numberstring.comma(current_number);
current_comma = comma(current_number);
current_string = numberstring(current_number, { 'cap': 'title', 'punc': '!' });

logger.info('Generated state from DynamoDB', {
Expand Down Expand Up @@ -545,7 +542,7 @@ async function countdown() {
logger.info('Decrementing number', { from: current_number, to: current_number - 1 });
current_number--;
current_string = numberstring(current_number, { 'cap': 'title', 'punc': '!' });
current_comma = numberstring.comma(current_number);
current_comma = comma(current_number);

logger.info('Updated countdown state', {
number: current_number,
Expand Down Expand Up @@ -950,7 +947,7 @@ app.get('/badge', async (req, res) => {
logger.info('Badge endpoint called');

// Use current_comma if available, otherwise fallback to START_NUMBER formatted
const badgeValue = current_comma || numberstring.comma(CONFIG.APP.START_NUMBER);
const badgeValue = current_comma || comma(CONFIG.APP.START_NUMBER);
logger.debug('Badge value', { badgeValue, hasCurrentComma: !!current_comma, isFallback: !current_comma });

const badge_url = `https://${CONFIG.BADGE.ALLOWED_DOMAIN}/badge/Von%20Countdown-${encodeURIComponent(badgeValue)}-a26d9e.svg`;
Expand Down Expand Up @@ -1064,6 +1061,6 @@ if (process.env.NODE_ENV !== 'test') {
}

// Export app for testing
module.exports = app;
export default app;

//*******************************************************************
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
export default {
testEnvironment: 'node',
testMatch: ['**/tests/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/tests/setup.js']
setupFilesAfterEnv: ['<rootDir>/tests/setup.js'],
transform: {}
};
Loading
Loading