diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..846f97f --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +JWT_SECRET=#jBhALXeYXC3$#e9 +RAPID_API_KEY= +IRC_SERVER=irc.libera.chat +IRC_CHANNEL="##usdev-dev" + +REDIS_HOST=localhost +REDIS_PASS=password + +S3_ENDPOINT="localhost" +S3_PORT=9000 +S3_USE_SSL=false +S3_ACCESS_KEY="localminio" +S3_SECRET_KEY="localminio" +S3_BUCKET="devbucket" diff --git a/.gitignore b/.gitignore index d2afab0..a5d4ee2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ lerna-debug.log* !.vscode/tasks.json !.vscode/launch.json .env +.env.bak !.vscode/extensions.json + +data/ diff --git a/README.md b/README.md index dc546f0..cbd9ea2 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,28 @@ -# api.us.dev +# us.dev Generalized API -## Description +AKA _the monolith_ -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. +## Quickstart -## Installation +Dependencies: -```bash -$ yarn install +- Docker +- Node 18 + +```sh +# Copy example .env +cp .env.example .env +# Install Dependencies +yarn +# Start local services +docker compose up -d +# Copy default data into local minio +cp -r default/* data/minio/devbucket +# Start Application +yarn start:dev ``` -## Running the app - -```bash -# development -$ yarn run start - -# watch mode -$ yarn run start:dev - -# production mode -$ yarn run start:prod -``` - -## Test - -```bash -# unit tests -$ yarn run test - -# e2e tests -$ yarn run test:e2e - -# test coverage -$ yarn run test:cov -``` - -## Support - -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). - -## Stay in touch - -- Author - [Kamil Myƛliwiec](https://kamilmysliwiec.com) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) - -## License - -Nest is [MIT licensed](LICENSE). +Visit http://localhost:3000/api ## Configuration diff --git a/docker-compose.yaml b/docker-compose.yaml index 27be9bd..2d5a336 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,20 @@ version: '3' services: + minio: + image: bitnami/minio + networks: + - db_net + ports: + - 9000:9000 + - 9001:9001 + volumes: + - ./data/minio:/bitnami/minio/data + environment: + - MINIO_ROOT_USER=localminio + - MINIO_ROOT_PASSWORD=localminio + - MINIO_DEFAULT_BUCKETS=devbucket + env_file: + - .env redis: image: redis networks: diff --git a/src/app.module.ts b/src/app.module.ts index fd6ab96..dc7a8b6 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -19,6 +19,7 @@ import { BullModule } from '@nestjs/bull'; import { ScheduleModule } from '@nestjs/schedule'; import { RedisClientOptions } from 'redis'; import { redisStore } from 'cache-manager-redis-yet'; +import { RedirectsModule } from './redirects/redirects.module'; @Module({ imports: [ @@ -72,8 +73,9 @@ import { redisStore } from 'cache-manager-redis-yet'; OgScraperModule, MinioModule, KvModule, + RedirectsModule, ], controllers: [AppController], providers: [AppService], }) -export class AppModule {} +export class AppModule { } diff --git a/src/config/configuration.ts b/src/config/configuration.ts index a303a7b..3036d94 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -10,6 +10,10 @@ export default () => ({ port: parseInt(process.env.IRC_PORT ?? '6697'), channel: process.env.IRC_CHANNEL ?? '#usdev', password: process.env.IRC_PASSWORD ?? '', + nick: + process.env.IRC_NICK ?? process.env.NODE_ENV === 'production' + ? 'us-bot' + : 'us-dev', }, redis: { host: process.env.REDIS_HOST ?? 'redis-master', diff --git a/src/ircbot/ircbot.service.ts b/src/ircbot/ircbot.service.ts index 4636563..b24e230 100644 --- a/src/ircbot/ircbot.service.ts +++ b/src/ircbot/ircbot.service.ts @@ -18,7 +18,7 @@ export class IrcbotService { public readonly domainrProxy: DomainrproxyService, ) { if (!this.configService.get('irc.enabled')) return; - const nick = process.env.NODE_ENV === 'production' ? 'us-bot' : 'us-dev'; + const nick = this.configService.get('irc.nick') || 'us-dev'; const ircPassword = this.configService.get('irc.password'); this.socket = connect({ port: this.configService.get('irc.port'), @@ -30,7 +30,7 @@ export class IrcbotService { if (ircPassword) this.client.pass(ircPassword); this.client.user(nick, `us.dev bot ${process.env.NODE_ENV}`); this.client.nick(nick); - // this.client.send('nickserv', `identify ${nick} ${ircPassword}`); + this.client.send('nickserv', `identify ${nick} ${ircPassword}`); console.log(nick); const channel: string = this.configService.get( 'irc.channel', diff --git a/src/minio/minio.service.ts b/src/minio/minio.service.ts index 98c463c..fae11ec 100644 --- a/src/minio/minio.service.ts +++ b/src/minio/minio.service.ts @@ -15,8 +15,8 @@ export class MinioService { ) { this.client = new Client({ endPoint: this.configService.get('S3_ENDPOINT', 's3.hooli.co'), - port: this.configService.get('S3_PORT', 443), - useSSL: true, + port: Number(this.configService.get('S3_PORT', 443)), + useSSL: this.configService.get('S3_USE_SSL', 'true') === 'true', accessKey: this.configService.get('S3_ACCESS_KEY', ''), secretKey: this.configService.get('S3_SECRET_KEY', ''), }); diff --git a/src/redirects/redirects.controller.ts b/src/redirects/redirects.controller.ts new file mode 100644 index 0000000..4204a87 --- /dev/null +++ b/src/redirects/redirects.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from '@nestjs/common'; + +@Controller('redirects') +export class RedirectsController {} diff --git a/src/redirects/redirects.module.ts b/src/redirects/redirects.module.ts new file mode 100644 index 0000000..e651331 --- /dev/null +++ b/src/redirects/redirects.module.ts @@ -0,0 +1,7 @@ +import { Module } from '@nestjs/common'; +import { RedirectsController } from './redirects.controller'; + +@Module({ + controllers: [RedirectsController] +}) +export class RedirectsModule {} diff --git a/src/redirects/required-reading.controller.ts b/src/redirects/required-reading.controller.ts new file mode 100644 index 0000000..2576566 --- /dev/null +++ b/src/redirects/required-reading.controller.ts @@ -0,0 +1,9 @@ +import { Controller, Get } from '@nestjs/common'; + +@Controller({ host: "requiredreading.dev" }) +export class RequiredReadingController { + @Get('') + getRoot() { + return "Hello required reading" + } +}