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

perf: vite-node + HMR 적용 #591

Merged
merged 5 commits into from
Jul 31, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ RUN pnpm -r run build

WORKDIR /app/backend

EXPOSE 3000
ENTRYPOINT [ "pnpm", "prod" ]
12 changes: 6 additions & 6 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.3.1 || >=18.16.1 <20.0.0"
},
"scripts": {
"start": "ts-node -r tsconfig-paths/register --project ./tsconfig.prod.json src/server.ts",
"start": "npx vite-node src/server.ts",
"build": "pnpm --filter='@jiphyeonjeon-42/contracts' build",
"dev": "nodemon --watch src --watch ../contracts/dist --exec ts-node src/server.ts",
"prod": "pnpm build && pnpm start",
"dev": "vite-node --watch src/server.ts",
"standalone": "npm run build && npm run start",
Comment on lines +13 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경된 명령어에 대해 어딘가 설명을 남겨주시면 감사드리겠습니다.
주석이나 README 혹은 docs 면 좋을 것 같습니다.

"lint": "eslint --fix --ext .js,.ts src",
"test": "jest"
},
Expand All @@ -38,10 +38,8 @@
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"jest": "^29.5.0",
"nodemon": "^2.0.22",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typeorm-model-generator": "^0.4.6",
"jest-mock-extended": "^3.0.4"
},
Expand Down Expand Up @@ -73,8 +71,10 @@
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.3.0",
"ts-pattern": "^5.0.1",
"tsconfig-paths": "^4.1.1",
"typeorm": "^0.3.11",
"vite": "^4.4.7",
"vite-node": "https://github.com/scarf005/vitest/releases/download/v0.33.0-2023-07-30/vite-node-0.33.0.tgz",
"vite-tsconfig-paths": "^4.2.0",
"winston": "^3.6.0",
"winston-daily-rotate-file": "^4.6.1"
}
Expand Down
14 changes: 9 additions & 5 deletions backend/src/app-data-source.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { DataSource, DataSourceOptions } from 'typeorm';
import { connectOption } from '~/config';
import { connectMode, connectOption } from '~/config';
import * as entities from '~/entity/entities';
import { logger } from './v1/utils/logger';

export const option: DataSourceOptions = {
type: 'mysql',
port: 3306,
...connectOption,
entities: [
`${__dirname}/**/entities/*.{js,ts}`,
],
entities: Object.values(entities),
logging: true,
// synchronize: true,
poolSize: 200,
};
console.log(__dirname);
logger.info(__dirname);
const jipDataSource = new DataSource(option);
await jipDataSource.initialize().then(() => {
logger.info('typeORM INIT SUCCESS');
logger.info(connectMode);
});

export default jipDataSource;
22 changes: 5 additions & 17 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import express from 'express';
import passport from 'passport';
import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import jipDataSource from '~/app-data-source';
import { connectMode } from '~/config';
import { logger, morganMiddleware } from '~/logger';
import { FtAuthentication, FtStrategy, JwtStrategy } from '~/v1/auth/auth.strategy';
import swaggerOptions from '~/v1/swagger/swagger';
import errorConverter from '~/v1/utils/error/errorConverter';
Expand All @@ -21,6 +18,7 @@ import { createExpressEndpoints } from '@ts-rest/express';

import router from '~/v1/routes';
import routerV2 from '~/v2/routes';
import { morganMiddleware } from './logger';

const app: express.Application = express();

Expand All @@ -38,30 +36,20 @@ app.use(
'http://42jip.com',
],
credentials: true,
})
}),
);

passport.use('42', FtStrategy);
passport.use('42Auth', FtAuthentication);
passport.use('jwt', JwtStrategy);

jipDataSource
.initialize()
.then(() => {
logger.info('typeORM INIT SUCCESS');
logger.info(connectMode);
})
.catch((e) => {
logger.error(`typeORM INIT FAILED : ${e.message}`);
});

// Swagger 연결
const specs = swaggerJsdoc(swaggerOptions);
app.get('/swagger.json', (_req, res) => res.json(specs));
app.use(
'/swagger',
swaggerUi.serveFiles(undefined, { swaggerUrl: '/swagger.json' }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/swagger.json' })
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/swagger.json' }),
);

const v2Specs = generateOpenApi(
Expand All @@ -74,13 +62,13 @@ const v2Specs = generateOpenApi(
},
{
setOperationId: false,
}
},
);
app.get('/docs.json', (_req, res) => res.json(v2Specs));
app.use(
'/docs',
swaggerUi.serveFiles(undefined, { swaggerUrl: '/docs.json' }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/docs.json' })
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/docs.json' }),
);

// dev route
Expand Down
14 changes: 6 additions & 8 deletions backend/src/entity/entities/Book.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn,
} from 'typeorm';
import BookInfo from './BookInfo';
import User from './User';
import Lending from './Lending';
import Reservation from './Reservation';
import { BookInfo } from './BookInfo';
import { User } from './User';
import { Lending } from './Lending';
import { Reservation } from './Reservation';

@Index('FK_donator_id_from_user', ['donatorId'], {})
@Entity('book')

class Book {
export class Book {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id?: number;

Expand All @@ -28,7 +28,7 @@ class Book {
})
createdAt?: Date;

@Column()
@Column('int')
infoId: number;

@Column('datetime', {
Expand Down Expand Up @@ -60,5 +60,3 @@ class Book {
@OneToMany(() => Reservation, (reservation) => reservation.book)
reservations?: Reservation[];
}

export default Book;
16 changes: 7 additions & 9 deletions backend/src/entity/entities/BookInfo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn,
} from 'typeorm';
import Book from './Book';
import Category from './Category';
import Likes from './Likes';
import Reservation from './Reservation';
import Reviews from './Reviews';
import SuperTag from './SuperTag';
import { Book } from './Book';
import { Category } from './Category';
import { Likes } from './Likes';
import { Reservation } from './Reservation';
import { Reviews } from './Reviews';
import { SuperTag } from './SuperTag';

@Index('categoryId', ['categoryId'], {})
@Entity('book_info')
class BookInfo {
export class BookInfo {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id?: number;

Expand Down Expand Up @@ -69,5 +69,3 @@ class BookInfo {
@OneToMany(() => SuperTag, (superTags) => superTags.userId)
superTags?: SuperTag[];
}

export default BookInfo;
6 changes: 2 additions & 4 deletions backend/src/entity/entities/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import BookInfo from './BookInfo';
import { BookInfo } from './BookInfo';

@Index('id', ['id'], { unique: true })
@Index('name', ['name'], { unique: true })
@Entity('category', { schema: '42library' })
class Category {
export class Category {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand All @@ -20,5 +20,3 @@ class Category {
@OneToMany(() => BookInfo, (bookInfo) => bookInfo.category)
bookInfos: BookInfo[];
}

export default Category;
10 changes: 4 additions & 6 deletions backend/src/entity/entities/Lending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import Book from './Book';
import User from './User';
import { Book } from './Book';
import { User } from './User';

@Index('FK_f2adde8c7d298210c39c500d966', ['lendingLibrarianId'], {})
@Index('FK_returningLibrarianId', ['returningLibrarianId'], {})
@Entity('lending', { schema: '42library' })

class Lending {
export class Lending {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down Expand Up @@ -81,6 +81,4 @@ class Lending {
})
@JoinColumn([{ name: 'returningLibrarianId', referencedColumnName: 'id' }])
returningLibrarian: User;
}

export default Lending;
}
10 changes: 4 additions & 6 deletions backend/src/entity/entities/Likes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import User from './User';
import BookInfo from './BookInfo';
import { User } from './User';
import { BookInfo } from './BookInfo';

@Index('FK_529dceb01ef681127fef04d755d4', ['userId'], {})
@Index('FK_bookInfo3', ['bookInfoId'], {})
@Entity('likes', { schema: '42library' })

class Likes {
export class Likes {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand All @@ -39,6 +39,4 @@ class Likes {
})
@JoinColumn([{ name: 'bookInfoId', referencedColumnName: 'id' }])
bookInfo: BookInfo;
}

export default Likes;
}
12 changes: 5 additions & 7 deletions backend/src/entity/entities/Reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import User from './User';
import BookInfo from './BookInfo';
import Book from './Book';
import { User } from './User';
import { BookInfo } from './BookInfo';
import { Book } from './Book';

@Index('FK_bookInfo', ['bookInfoId'], {})
@Entity('reservation')
class Reservation {
export class Reservation {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down Expand Up @@ -63,6 +63,4 @@ class Reservation {

@Column('int', { name: 'bookId', nullable: true })
bookId: number | null;
}

export default Reservation;
}
10 changes: 4 additions & 6 deletions backend/src/entity/entities/Reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import User from './User';
import BookInfo from './BookInfo';
import { User } from './User';
import { BookInfo } from './BookInfo';

@Index('FK_529dceb01ef681127fef04d755d3', ['userId'], {})
@Index('FK_bookInfo2', ['bookInfoId'], {})
@Entity('reviews')

class Reviews {
export class Reviews {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down Expand Up @@ -66,6 +66,4 @@ class Reviews {
})
@JoinColumn([{ name: 'bookInfoId', referencedColumnName: 'id' }])
bookInfo: BookInfo;
}

export default Reviews;
}
6 changes: 3 additions & 3 deletions backend/src/entity/entities/SubTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import User from './User';
import SuperTag from './SuperTag';
import { User } from './User';
import { SuperTag } from './SuperTag';

@Index('userId', ['userId'], {})
@Index('superTagId', ['superTagId'], {})
@Entity('sub_tag', { schema: 'jip_dev' })
export default class SubTag {
export class SubTag {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down
8 changes: 4 additions & 4 deletions backend/src/entity/entities/SuperTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import SubTag from './SubTag';
import User from './User';
import BookInfo from './BookInfo';
import { SubTag } from './SubTag';
import { User } from './User';
import { BookInfo } from './BookInfo';

@Index('userId', ['userId'], {})
@Index('bookInfoId', ['bookInfoId'], {})
@Entity('super_tag', { schema: 'jip_dev' })
export default class SuperTag {
export class SuperTag {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down
18 changes: 8 additions & 10 deletions backend/src/entity/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import {
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import Book from './Book';
import Lending from './Lending';
import Likes from './Likes';
import Reservation from './Reservation';
import Reviews from './Reviews';
import SubTag from './SubTag';
import SuperTag from './SuperTag';
import { Book } from './Book';
import { Lending } from './Lending';
import { Likes } from './Likes';
import { Reservation } from './Reservation';
import { Reviews } from './Reviews';
import { SubTag } from './SubTag';
import { SuperTag } from './SuperTag';

@Index('email', ['email'], { unique: true })
@Index('intraId', ['intraId'], { unique: true })
@Index('slack', ['slack'], { unique: true })
@Entity('user')
class User {
export class User {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

Expand Down Expand Up @@ -89,5 +89,3 @@ class User {
@OneToMany(() => SuperTag, (superTags) => superTags.userId)
superTags: SuperTag[];
}

export default User;