issue # gitlab-ci 테스트
This commit is contained in:
@@ -5,9 +5,10 @@ import { DbModule } from './db/db.module';
|
||||
import { RedisModule } from './redis/redis.module';
|
||||
import { AccountModule } from './modules/account/account.module';
|
||||
import { MailerModule } from './util/mailer/mailer.module';
|
||||
import { AppConfigModule } from './config/config.module';
|
||||
|
||||
@Module({
|
||||
imports: [DbModule, RedisModule, MailerModule, AccountModule],
|
||||
imports: [AppConfigModule, DbModule, RedisModule, MailerModule, AccountModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
15
src/config/config.module.ts
Normal file
15
src/config/config.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
envFilePath: [
|
||||
'.env.common',
|
||||
`.env.${process.env.NODE_ENV}`
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
export class AppConfigModule{}
|
||||
@@ -1,20 +1,22 @@
|
||||
import { Global, Module } from "@nestjs/common";
|
||||
import { Pool } from "pg";
|
||||
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
import * as schema from '../../drizzle/schema';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
providers: [
|
||||
{
|
||||
provide: "DRIZZLE",
|
||||
useFactory: (): NodePgDatabase<typeof schema> => {
|
||||
useFactory: (configService: ConfigService): NodePgDatabase<typeof schema> => {
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.PG_DATABASE_URL
|
||||
connectionString: configService.get<string>('PG_DATABASE_URL')
|
||||
});
|
||||
|
||||
return drizzle(pool, { schema: schema });
|
||||
}
|
||||
},
|
||||
inject: [ConfigService]
|
||||
}
|
||||
],
|
||||
exports: ["DRIZZLE"]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Global, Module } from "@nestjs/common";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
import Redis from "ioredis";
|
||||
|
||||
@Global()
|
||||
@@ -6,12 +7,13 @@ import Redis from "ioredis";
|
||||
providers: [
|
||||
{
|
||||
provide: "REDIS",
|
||||
useFactory: (): Redis => {
|
||||
useFactory: (configService: ConfigService): Redis => {
|
||||
return new Redis({
|
||||
host: process.env.RD_HOST!,
|
||||
port: Number(process.env.RD_PORT || 6779)
|
||||
host: configService.get<string>('RD_HOST')!,
|
||||
port: configService.get<number>('RD_PORT')
|
||||
});
|
||||
}
|
||||
},
|
||||
inject: [ConfigService]
|
||||
},
|
||||
],
|
||||
exports: ["REDIS"]
|
||||
|
||||
@@ -1,42 +1,54 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import nodemailer from 'nodemailer';
|
||||
import { google } from 'googleapis';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class MailerService {
|
||||
private oauth2Client = new google.auth.OAuth2(
|
||||
process.env.GMAIL_CLIENT_ID,
|
||||
process.env.GMAIL_CLIENT_SECRET,
|
||||
'https://developers.google.com/oauthplayground'
|
||||
);
|
||||
private oauth2Client: OAuth2Client;
|
||||
private readonly gmailUser: string;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const clientId = this.configService.get<string>('GMAIL_CLIENT_ID');
|
||||
const clientSecret = this.configService.get<string>('GMAIL_CLIENT_SECRET');
|
||||
const refreshToken = this.configService.get<string>('GMAIL_REFRESH_TOKEN');
|
||||
|
||||
this.gmailUser = this.configService.get<string>('GMAIL_USER')!;
|
||||
|
||||
this.oauth2Client = new google.auth.OAuth2(
|
||||
clientId,
|
||||
clientSecret,
|
||||
'https://developers.google.com/oauthplayground'
|
||||
);
|
||||
|
||||
constructor() {
|
||||
this.oauth2Client.setCredentials({
|
||||
refresh_token: process.env.GMAIL_REFRESH_TOKEN
|
||||
refresh_token: refreshToken,
|
||||
});
|
||||
}
|
||||
|
||||
async sendMail(to: string, subject: string, html: string) {
|
||||
const accessToken = await this.oauth2Client.getAccessToken();
|
||||
|
||||
const options: SMTPTransport.Options = {
|
||||
host: "smtp.gmail.com",
|
||||
port: 465,
|
||||
secure: true,
|
||||
auth: {
|
||||
type: "OAuth2",
|
||||
user: process.env.GMAIL_USER,
|
||||
clientId: process.env.GMAIL_CLIENT_ID,
|
||||
clientSecret: process.env.GMAIL_CLIENT_SECRET,
|
||||
refreshToken: process.env.GMAIL_REFRESH_TOKEN,
|
||||
accessToken: accessToken?.token || ''
|
||||
user: this.gmailUser,
|
||||
clientId: this.configService.get<string>('GMAIL_CLIENT_ID'),
|
||||
clientSecret: this.configService.get<string>('GMAIL_CLIENT_SECRET'),
|
||||
refreshToken: this.configService.get<string>('GMAIL_REFRESH_TOKEN'),
|
||||
accessToken: accessToken?.token || '',
|
||||
}
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(options);
|
||||
|
||||
return transporter.sendMail({
|
||||
from: `Scheduler ${process.env.GMAIL_USER}>`,
|
||||
from: `Scheduler ${this.gmailUser}>`,
|
||||
to,
|
||||
subject,
|
||||
html
|
||||
|
||||
Reference in New Issue
Block a user