Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: social - redis #113

Merged
merged 3 commits into from
Jun 13, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ jobs:
- name: Deploy
env:
FLY_APP_NAME: ${{ vars.FLY_APP_NAME }}
FLY_CONFIG_FILE_NAME: ${{ github.ref == 'refs/heads/main' && 'fly.prod.toml' || 'flu.stage.toml' }}
run: |
~/.fly/bin/fly deploy \
--config fly.toml \
--config $FLY_CONFIG_FILE_NAME \
--dockerfile Dockerfile \
--app $FLY_APP_NAME \
--access-token $FLY_ACCESS_TOKEN
33 changes: 33 additions & 0 deletions fly.prod.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
primary_region = "syd"

[http_service]
internal_port = 4200
force_https = true
auto_stop_machines = false
auto_start_machines = false
min_machines_running = 1
[http_service.concurrency]
type = "requests"
soft_limit = 500
hard_limit = 750

[http_service.tls_options]
alpn = ["h2", "http/1.1"]
versions = ["TLSv1.2", "TLSv1.3"]
default_self_signed = true

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "10s"
path = "/api/health"
protocol = "http"
port = 4200
tls_skip_verify = true

[[vm]]
size = "shared-cpu-1x"
memory = "512mb"
cpus = 1
cpu_kind = "shared"
4 changes: 2 additions & 2 deletions fly.toml → fly.stage.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ primary_region = "syd"
[http_service]
internal_port = 4200
force_https = true
auto_stop_machines = false
auto_start_machines = false
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
[http_service.concurrency]
type = "requests"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"cheerio": "1.0.0-rc.12",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"connect-redis": "^7.1.1",
"crypto-js": "^4.2.0",
"expo-server-sdk": "^3.10.0",
"express": "^4.19.2",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { Inject, MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AuthModule } from '../auth/auth.module';
import { UserModule } from '../user/user.module';
Expand All @@ -14,6 +14,10 @@ import { ConnectionsModule } from '../../src/connections/connections.module';
import { AppLoggerMiddleware } from '../../src/middlewares/logger.middleware';
import { CommonModule } from '../common/common.module';
import { NotificationsModule } from '../../src/notifications/notifications.module';
import RedisStore from 'connect-redis';
import * as session from 'express-session';
import Redis from 'ioredis';
import { REDIS_CLIENT } from '../../src/provider/redis.provider';

@Module({
imports: [
Expand All @@ -40,7 +44,19 @@ import { NotificationsModule } from '../../src/notifications/notifications.modul
],
})
export class AppModule implements NestModule {
constructor(@Inject(REDIS_CLIENT) private redis: Redis) {}

configure(consumer: MiddlewareConsumer): void {
consumer.apply(AppLoggerMiddleware).forRoutes('*');
consumer
.apply(
AppLoggerMiddleware,
session({
secret: process.env.SESSION_SECRET || 'lala',
resave: false,
saveUninitialized: false,
store: new RedisStore({ client: this.redis }),
}),
)
.forRoutes('*');
}
}
4 changes: 2 additions & 2 deletions src/auth/service/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ export class AuthService {
}

async handleAppleOAuthLogin(req: any) {
const { email, name } = req.user;
const displayName = name.firstName + ' ' + name.lastName;
const { email, displayName } = req.user;
const user = await this.createUserIfNotExists(
email,
AuthType.APPLE,
displayName,
null,
false,
);

const token = await this.generateToken(user);
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AppModule } from './app/app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { json } from 'express';
import * as session from 'express-session';

function initializeSwagger(app: any) {
const config = new DocumentBuilder()
Expand All @@ -19,7 +18,6 @@ function initializeSwagger(app: any) {
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.use(session({ secret: process.env.SESSION_SECRET }));

app.setGlobalPrefix(globalPrefix);
app.enableCors();
Expand Down
Loading