Skip to content

Commit

Permalink
3rd_Seminar Level 2 초기세팅
Browse files Browse the repository at this point in the history
Related to: #5
  • Loading branch information
Crayon committed Apr 28, 2022
1 parent 3da9d97 commit d154664
Show file tree
Hide file tree
Showing 11 changed files with 2,697 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 3rd_Seminar/assignment2/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["dist/", "node_modules/"],
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
150 changes: 150 additions & 0 deletions 3rd_Seminar/assignment2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

# End of https://www.toptal.com/developers/gitignore/api/node

# .env
.env.development
.env.production
.env.test
12 changes: 12 additions & 0 deletions 3rd_Seminar/assignment2/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "consistent",
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
3 changes: 3 additions & 0 deletions 3rd_Seminar/assignment2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
28 changes: 28 additions & 0 deletions 3rd_Seminar/assignment2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "express-example",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist"
},
"dependencies": {
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"dotenv": "^16.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.18.0"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"nodemon": "^2.0.15",
"routing-controllers": "^0.9.0",
"typescript": "^4.6.3"
}
}
27 changes: 27 additions & 0 deletions 3rd_Seminar/assignment2/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import express from 'express';
import { useExpressServer } from 'routing-controllers';
import { routingControllerOptions } from './util/RoutingConfig';

export class App {
public app: express.Application;

constructor() {
this.app = express();
}

/**
* Express를 시작한다.
* @param port 포트
*/
public async createExpressServer(port: number): Promise<void> {
try {
useExpressServer(this.app, routingControllerOptions);

this.app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
} catch (error) {
console.log(error);
}
}
}
25 changes: 25 additions & 0 deletions 3rd_Seminar/assignment2/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require('dotenv').config({
path: `../config/.env.${process.env.NODE_ENV || 'development'}`,
});

/**
* 환경 변수
*/
export const env = {
isDevelopment: process.env.NODE_ENV === 'development',
isProduction: process.env.NODE_ENV === 'production',
isTest: process.env.NODE_ENV === 'test',
app: {
port: Number(process.env.PORT) || 3000,
apiPrefix: process.env.API_PREFIX || '/api',
},
database: {
host: process.env.DATABASE_HOST,
port: Number(process.env.DATABASE_PORT) || 3306,
usename: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
name: process.env.DATABASE_NAME,
synchronize: process.env.TYPEORM_SYNCHRONIZE === 'true',
logging: process.env.TYPEORM_LOGGING === 'true',
},
};
11 changes: 11 additions & 0 deletions 3rd_Seminar/assignment2/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { App } from './app';
import { env } from './env';

try {
const app = new App();
const port: number = env.app.port;

app.createExpressServer(port);
} catch (error) {
console.log(error);
}
6 changes: 6 additions & 0 deletions 3rd_Seminar/assignment2/src/util/RoutingConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { env } from '../env';

export const routingControllerOptions = {
routePrefix: env.app.apiPrefix,
controller: [`${__dirname}/../controller/*{.ts,.js}`],
};
28 changes: 28 additions & 0 deletions 3rd_Seminar/assignment2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es6", // 어떤 버전으로 컴파일
"allowSyntheticDefaultImports": true, // default export가 없는 모듈에서 default imports를 허용
"experimentalDecorators": true, // decorator 실험적 허용
"emitDecoratorMetadata": true, // 데코레이터가 있는 선언에 대해 특정 타입의 메타 데이터를 내보내는 실험적인 지원
"skipLibCheck": true, // 정의 파일 타입 체크 여부
"moduleResolution": "node", // commonJS -> node 에서 동작
"module": "commonjs", // import 문법
"strict": true, // 타입 검사 엄격하게
"pretty": true, // error 메시지 예쁘게
"sourceMap": true, // 소스맵 파일 생성 -> .ts가 .js 파일로 트랜스 시 .js.map 생성
"outDir": "./dist", // 트랜스 파일 (.js) 저장 경로
"allowJs": true, // js 파일 ts에서 import 허용
"esModuleInterop": true, // ES6 모듈 사양을 준수하여 CommonJS 모듈을 가져올 수 있게 허용
"typeRoots": [
"./src/types/express.d.ts", // 타입(*.d.ts)파일을 가져올 디렉토리 설정
"./node_modules/@types" // 설정 안할시 기본적으로 ./node_modules/@types
]
},
"include": [
"./src/**/*" // build 시 포함
],
"exclude": [
"node_modules", // build 시 제외
"tests"
]
}
Loading

0 comments on commit d154664

Please sign in to comment.