Skip to content

Commit cab80d7

Browse files
committed
first commit
1 parent 1712348 commit cab80d7

11 files changed

+2345
-0
lines changed

.gitignore

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
node_modules/
2+
config/
3+
.DS_Store
4+
5+
# Created by https://www.toptal.com/developers/gitignore/api/node,vscode
6+
# Edit at https://www.toptal.com/developers/gitignore?templates=node,vscode
7+
8+
### Node ###
9+
# Logs
10+
logs
11+
*.log
12+
npm-debug.log*
13+
yarn-debug.log*
14+
yarn-error.log*
15+
lerna-debug.log*
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
*.lcov
32+
33+
# nyc test coverage
34+
.nyc_output
35+
36+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
37+
.grunt
38+
39+
# Bower dependency directory (https://bower.io/)
40+
bower_components
41+
42+
# node-waf configuration
43+
.lock-wscript
44+
45+
# Compiled binary addons (https://nodejs.org/api/addons.html)
46+
build/Release
47+
48+
# Dependency directories
49+
node_modules/
50+
jspm_packages/
51+
52+
# TypeScript v1 declaration files
53+
typings/
54+
55+
# TypeScript cache
56+
*.tsbuildinfo
57+
58+
# Optional npm cache directory
59+
.npm
60+
61+
# Optional eslint cache
62+
.eslintcache
63+
64+
# Microbundle cache
65+
.rpt2_cache/
66+
.rts2_cache_cjs/
67+
.rts2_cache_es/
68+
.rts2_cache_umd/
69+
70+
# Optional REPL history
71+
.node_repl_history
72+
73+
# Output of 'npm pack'
74+
*.tgz
75+
76+
# Yarn Integrity file
77+
.yarn-integrity
78+
79+
# dotenv environment variables file
80+
.env
81+
.env.test
82+
.env*.local
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
91+
# Nuxt.js build / generate output
92+
.nuxt
93+
dist
94+
95+
# Gatsby files
96+
.cache/
97+
# Comment in the public line in if your project uses Gatsby and not Next.js
98+
# https://nextjs.org/blog/next-9-1#public-directory-support
99+
# public
100+
101+
# vuepress build output
102+
.vuepress/dist
103+
104+
# Serverless directories
105+
.serverless/
106+
107+
# FuseBox cache
108+
.fusebox/
109+
110+
# DynamoDB Local files
111+
.dynamodb/
112+
113+
# TernJS port file
114+
.tern-port
115+
116+
# Stores VSCode versions used for testing VSCode extensions
117+
.vscode-test
118+
119+
### vscode ###
120+
.vscode/*
121+
!.vscode/settings.json
122+
!.vscode/tasks.json
123+
!.vscode/launch.json
124+
!.vscode/extensions.json
125+
*.code-workspace
126+
127+
# End of https://www.toptal.com/developers/gitignore/api/node,vscode

app.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const express = require('express');
2+
const bodyParser = require('body-parser');
3+
const app = express();
4+
const {sequelize} = require('./models');
5+
const indexRouter = require('./routes/index');
6+
7+
sequelize.sync({ alter : false})
8+
.then(() => {
9+
console.log('데이터베이스 연결 성공');
10+
})
11+
.catch((error) => {
12+
console.error(error);
13+
})
14+
15+
app.use(bodyParser.urlencoded({extended : true}));
16+
app.use(bodyParser.json());
17+
app.use('/', indexRouter);
18+
19+
// error handler
20+
app.use(function(err, req, res, next) {
21+
// set locals, only providing error in development
22+
res.locals.message = err.message;
23+
res.locals.error = req.app.get('env') === 'development' ? err : {};
24+
25+
// render the error page
26+
res.status(err.status || 500);
27+
res.render('error');
28+
});
29+
30+
31+
const port = 3002;
32+
app.listen(port, ()=> console.log(`app listening on port ${port}!`));

models/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Sequelize = require('sequelize');
2+
const env = process.env.NODE_ENV || 'development';
3+
const config = require('../config/config.json')[env];
4+
const db = {};
5+
let sequelize;
6+
if (config.use_env_variable) {
7+
sequelize = new Sequelize(process.env[config.use_env_variable], config);
8+
} else {
9+
sequelize = new Sequelize(config.database, config.username, config.password, config);
10+
}
11+
db.sequelize = sequelize;
12+
db.Sequelize = Sequelize;
13+
14+
15+
16+
module.exports = db;

models/user.js

Whitespace-only changes.

modules/jwt.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const jwt = require('jsonwebtoken');
2+
const {
3+
secretKey,
4+
options,
5+
} = require('../config/secretKey');
6+
const TOKEN_EXPIRED = -3;
7+
const TOKEN_INVALID = -2;
8+
9+
module.exports = {
10+
sign: async (user) => {
11+
const payload = {
12+
id: user.id,
13+
};
14+
const result = {
15+
token: jwt.sign(payload, secretKey, options),
16+
};
17+
return result;
18+
},
19+
verify: async (token) => {
20+
let decoded;
21+
try {
22+
decoded = jwt.verify(token, secretKey);
23+
} catch (err) {
24+
if (err.message === 'jwt expired') {
25+
console.log('expired token');
26+
return TOKEN_EXPIRED;
27+
} else if (err.message === 'invalid token') {
28+
console.log('invalid token');
29+
console.log(TOKEN_INVALID);
30+
return TOKEN_INVALID;
31+
} else {
32+
console.log("invalid token");
33+
return TOKEN_INVALID;
34+
}
35+
}
36+
return decoded;
37+
}
38+
}

modules/responseMessage.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
NULL_VALUE: "필요한 값이 없습니다.",
3+
OUT_OF_VALUE: "파라미터 값이 잘못 되었습니다.",
4+
5+
/* 토큰 */
6+
EMPTY_TOKEN: '토큰 값이 없습니다.',
7+
EXPIRED_TOKEN: '토큰 값이 만료되었습니다.',
8+
INVALID_TOKEN: '유효하지 않은 토큰값입니다.',
9+
AUTH_SUCCESS: '인증에 성공했습니다.',
10+
ISSUE_SUCCESS: '새로운 토큰이 생성되었습니다.',
11+
12+
/* User */
13+
READ_USER_SUCCESS: "사용자 조회 성공",
14+
READ_USER_ALL_SUCCESS: "전체 사용자 조회 실패",
15+
READ_USER_FAIL: "사용자 조회 성공",
16+
READ_USER_ALL_FAIL: "전체 사용자 조회 실패",
17+
UPDATE_USER_SUCCESS: "사용자 업데이트 성공",
18+
UPDATE_USER_FAIL: "사용자 업데이트 실패",
19+
DELETE_USER_SUCCESS: "사용자 삭제 성공",
20+
DELETE_USER_FAIL: "사용자 삭제 실패",
21+
22+
/* 회원가입 */
23+
SIGN_UP_SUCCESS: "회원 가입 성공.",
24+
SIGN_UP_FAIL: "회원 가입 실패.",
25+
SIGN_IN_SUCCESS: "로그인 성공.",
26+
SIGN_IN_FAIL: "로그인 실패.",
27+
ALREADY_ID: "존재하는 ID 입니다.",
28+
NO_USER: "존재하지않는 유저 id 입니다.",
29+
ALREADY_EMAIL: "이미 존재하는 이메일 입니다.",
30+
NO_EMAIL: '존재하지 않는 이메일 입니다.',
31+
MISS_MATCH_PW: "비밀번호가 일치하지 않습니다",
32+
33+
/* 서버에러 */
34+
INTERNAL_SERVER_ERROR: "서버 내부 오류",
35+
}
36+

modules/statusCode.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
OK: 200,
3+
CREATED: 201,
4+
NO_CONTENT: 204,
5+
RESET_CONTENT: 205,
6+
NOT_MODIFIED: 304,
7+
BAD_REQUEST: 400,
8+
UNAUTHORIZED: 401,
9+
FORBIDDEN: 403,
10+
NOT_FOUND: 404,
11+
INTERNAL_SERVER_ERROR: 500,
12+
SERVICE_UNAVAILABLE: 503,
13+
};

modules/util.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
success: (status, message, data) => ({
3+
status,
4+
success: true,
5+
message,
6+
data,
7+
}),
8+
fail: (status, message) => ({
9+
status,
10+
success: false,
11+
message,
12+
}),
13+
};

0 commit comments

Comments
 (0)