Skip to content

Commit

Permalink
Merge pull request #106 from ljlm0402/development
Browse files Browse the repository at this point in the history
🌼 Update Version - v6.0.0
  • Loading branch information
ljlm0402 authored Jul 13, 2021
2 parents a541c8c + 0f7caa2 commit 872ee2d
Show file tree
Hide file tree
Showing 60 changed files with 1,537 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ $ npx typescript-express-starter "project name"
| Mongoose | Node.js와 MongoDB를 위한 ODM(Object Data Mapping) 라이브러리 |
| TypeORM | 자바스크립트, 타입스크립트과 함께 사용되어 Node.js, React Native, Expo에서 실행될 수 있는 ORM |
| Prisma | 데이터베이스에 데이터를 프로그래밍 언어의 객체와 매핑하여 기존에 SQL로 작성하던 데이터를 수정, 테이블 구조 변경등의 작업을 객체를 통해 프로그래밍적으로 할 수 있도록 해주는 ORM |
| Knex (개발중) | 쿼리 빌더를 위한 라이브러리 |
| Knex | 쿼리 빌더를 위한 라이브러리 |
| GraphQL (개발중) | API 용 쿼리 언어이며 기존 데이터로 이러한 쿼리를 수행하기위한 런타임 |

## 🛎 Script 명령어
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Start your typescript-express-starter app in development mode at `http://localho
| Mongoose | MongoDB Object Modeling(ODM) designed to work in an asynchronous environment |
| TypeORM | An ORM that can run in Node.js and Others |
| Prisma | Modern Database Access for TypeScript & Node.js |
| Knex (Developing) | SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle |
| Knex | SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle |
| GraphQL (Developing) | query language for APIs and a runtime for fulfilling those queries with your existing data |

## 🛎 Available Commands for the Server
Expand Down
18 changes: 18 additions & 0 deletions lib/knex/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# compiled output
.vscode
/node_modules

# code formatter
.eslintrc
.eslintignore
.editorconfig
.huskyrc
.lintstagedrc.json
.prettierrc

# test
jest.config.js

# docker
Dockerfile
docker-compose.yml
9 changes: 9 additions & 0 deletions lib/knex/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions lib/knex/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=3000
1 change: 1 addition & 0 deletions lib/knex/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
18 changes: 18 additions & 0 deletions lib/knex/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["prettier", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-parameter-properties": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
5 changes: 5 additions & 0 deletions lib/knex/.huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
5 changes: 5 additions & 0 deletions lib/knex/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"*.ts": [
"npm run lint"
]
}
8 changes: 8 additions & 0 deletions lib/knex/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 150,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"arrowParens": "avoid"
}
35 changes: 35 additions & 0 deletions lib/knex/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"request": "launch",
"name": "Dev typescript-express-starter",
"command": "npm run dev"
},
{
"type": "node-terminal",
"request": "launch",
"name": "Start typescript-express-starter",
"command": "npm run start"
},
{
"type": "node-terminal",
"request": "launch",
"name": "Test typescript-express-starter",
"command": "npm run test"
},
{
"type": "node-terminal",
"request": "launch",
"name": "Lint typescript-express-starter",
"command": "npm run lint"
},
{
"type": "node-terminal",
"request": "launch",
"name": "Lint:Fix typescript-express-starter",
"command": "npm run lint:fix"
}
]
}
6 changes: 6 additions & 0 deletions lib/knex/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": false
}
24 changes: 24 additions & 0 deletions lib/knex/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Common build stage
FROM node:14.14.0-alpine3.12 as common-build-stage

COPY . ./app

WORKDIR /app

RUN npm install

EXPOSE 3000

# Dvelopment build stage
FROM common-build-stage as development-build-stage

ENV NODE_ENV development

CMD ["npm", "run", "dev"]

# Production build stage
FROM common-build-stage as production-build-stage

ENV NODE_ENV production

CMD ["npm", "run", "start"]
6 changes: 6 additions & 0 deletions lib/knex/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
docker build -t ${tag} .
clean:
docker rmi -f ${tag}
run:
docker run -d -p ${port}:${port} --name ${name} ${tag}
50 changes: 50 additions & 0 deletions lib/knex/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3.7'

services:
proxy:
image: nginx:alpine
container_name: proxy
ports:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
restart: 'unless-stopped'
networks:
- backend
server:
build:
context: ./
target: development-build-stage
dockerfile: Dockerfile
container_name: server
ports:
- '3000:3000'
volumes:
- ./:/app
- /app/node_modules
restart: 'unless-stopped'
networks:
- backend
links:
- mysql
depends_on:
- mysql
mysql:
image: mysql:5.7
container_name: mysql
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- '3306:3306'
networks:
- backend

networks:
backend:
driver: bridge

volumes:
data:
driver: local
43 changes: 43 additions & 0 deletions lib/knex/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
apps: [
{
name: 'myapp',
// package.json에 정의된 npm run start를 실행하게 해서 PM2로 관리하게 한다.
script: 'npm',
args: 'run dev',
instances: 2,
autorestart: true,
watch: false,
max_memory_restart: '1G',
// development mode
// pm2 start ecosystem.config.js
env: {
HOST: '0.0.0.0',
PORT: 3000,
NODE_ENV: 'development'
},
// production mode
// pm2 start ecosystem.config.js --env production
env_production: {
HOST: '0.0.0.0',
PORT: 3000,
NODE_ENV: 'production'
},
output: './logs/console.log',
error: './logs/consoleError.log'
}
],

deploy: {
production: {
// sample
user: 'node',
host: '123.12.123.1',
ref: 'origin/master',
repo: '[email protected]:repo.git',
path: '/var/www/production',
'post-deploy':
'npm install && pm2 reload ecosystem.config.js --env production'
}
}
}
12 changes: 12 additions & 0 deletions lib/knex/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig.json');

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src' }),
};
27 changes: 27 additions & 0 deletions lib/knex/knexfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
process.env['NODE_CONFIG_DIR'] = __dirname + '/src/configs';

import config from 'config';
import { dbConfig } from './src/interfaces/db.interface';

const db: dbConfig = config.get('dbConfig');
export = {
client: 'mysql',
connection: {
charset: 'utf8',
timezone: 'UTC',
host: db.host,
user: db.user,
password: db.password,
database: db.database,
port: db.port,
},
migrations: {
directory: 'src/databases/migrations',
tableName: 'migrations',
// stub: 'src/databases/stubs',
},
seeds: {
directory: 'src/databases/seeds',
// stub: 'src/databases/stubs',
},
};
40 changes: 40 additions & 0 deletions lib/knex/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

upstream api-server {
server server:3000;
keepalive 100;
}

server {
listen 80;
server_name localhost;

location / {
proxy_http_version 1.1;
proxy_pass http://api-server;
}

}

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
12 changes: 12 additions & 0 deletions lib/knex/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"watch": [
"src",
".env"
],
"ext": "js,ts,json",
"ignore": [
"src/**/*.spec.ts",
"src/**/*.test.ts"
],
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts"
}
Loading

0 comments on commit 872ee2d

Please sign in to comment.