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

[Add] : seminar2 level1 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions seminar_2/createServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const http = require('http');

http.createServer((req, res) => {
res.write('<h1>Hello Server Part</h1>');
res.end('<p>Server Love</p>');
}).listen(8080, () => {
console.log('8080번 포트에서 서버 대기 중입니다!');
});
145 changes: 145 additions & 0 deletions seminar_2/express/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

# 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
11 changes: 11 additions & 0 deletions seminar_2/express/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"watch": [
"src",
".env"
],
"ext": "js,ts,json",
"ignore": [
"src/**/*.spec.ts"
],
"exec": "ts-node --transpile-only ./src/index.ts"
}
15 changes: 15 additions & 0 deletions seminar_2/express/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "express",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist"
},
"dependencies": {
"@types/express": "^4.17.13",
"express": "^4.18.0",
"nodemon": "^2.0.15"
}
}
7 changes: 7 additions & 0 deletions seminar_2/express/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import express, { Router } from 'express';

const router: Router = express.Router();

router.use('/user', require('./user'));

module.exports = router;
12 changes: 12 additions & 0 deletions seminar_2/express/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express, { Request, Response, Router } from 'express';

const router: Router = express.Router();

router.get('/', (req: Request, res: Response) => {
return res.status(200).json({
status: 200,
message: '유저 조회 성공'
});
});

module.exports = router;
19 changes: 19 additions & 0 deletions seminar_2/express/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express, { Request, Response, NextFunction } from 'express';

const app = express();

app.use(express.json());

app.use('/api', require('./api'));

app.get('/', (req: Request, res: Response, next: NextFunction) => {
res.send('hello world');
});

app.listen('8000', () => {
console.log(`
#############################################
🛡️ Server listening on port: 8000 🛡️
#############################################
`);
});
28 changes: 28 additions & 0 deletions seminar_2/express/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