Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김현기
/
KindOfYourDog
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김현기
2020-06-13 03:13:35 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6b2b79ed6eb8cc432cf6e39dca8b56bcefebfec4
6b2b79ed
1 parent
7e4ae5d9
aws cognito를 이용해 AWS 엑세스 키에 대한 접근 방지 후 S3와 연결
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
24 deletions
app.js
createBucket.js
routes/index.js
app.js
View file @
6b2b79e
...
...
@@ -3,9 +3,33 @@ var express = require('express');
var
path
=
require
(
'path'
);
var
cookieParser
=
require
(
'cookie-parser'
);
var
logger
=
require
(
'morgan'
);
var
AWS
=
require
(
'aws-sdk'
);
// 이미지를 저장할 버킷 이름
var
bucketName
=
"kindofyourdog"
;
// s3 버킷의 엔드 포인트
var
bucketRegion
=
"ap-northeast-2"
;
// AWS Cognito 인증
var
IdentityPoolId
=
"ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be"
;
// AWS의 config 정보를 Update해준다 -> 이용자가 S3 버킷에 접근 가능하다
AWS
.
config
.
update
({
region
:
bucketRegion
,
credentials
:
new
AWS
.
CognitoIdentityCredentials
({
IdentityPoolId
:
IdentityPoolId
})
})
// 내가 사용할 S3
var
s3
=
new
aws
.
S3
({
apiVersion
:
"2006-03-01"
,
params
:
{
Bucket
:
bucketName
}
});
var
indexRouter
=
require
(
'./routes/index'
);
var
usersRouter
=
require
(
'./routes/users'
);
// image업로드 시 해당 route기능 사용
var
imageUploadRouter
=
require
(
'./routes/imageUpload'
);
var
app
=
express
();
...
...
@@ -21,6 +45,8 @@ app.use(express.static(path.join(__dirname, 'public')));
app
.
use
(
'/'
,
indexRouter
);
app
.
use
(
'/users'
,
usersRouter
);
//이미지 업로드
app
.
use
(
'/upload'
,
imageUploadRouter
);
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
...
...
createBucket.js
deleted
100644 → 0
View file @
7e4ae5d
const
AWS
=
require
(
'aws-sdk'
);
const
ID
=
'id'
;
const
SECRET
=
'secret'
;
const
BUCKET_NAME
=
'dogpicture-dizzi'
;
const
s3
=
new
AWS
.
S3
({
accessKeyId
:
ID
,
secretAccessKey
:
SECRET
});
const
params
=
{
Bucket
:
BUCKET_NAME
,
CreateBucketConfiguration
:
{
//Set your regieon here
LocationConstraint
:
"us-east-1"
}
};
s3
.
createBucket
(
params
,
function
(
err
,
data
)
{
if
(
err
)
console
.
log
(
err
,
err
.
stack
);
else
console
.
log
(
'Bucket Created Successfully'
,
data
.
Location
);
});
\ No newline at end of file
routes/index.js
View file @
6b2b79e
...
...
@@ -3,7 +3,11 @@ var router = express.Router();
/* GET home page. */
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'index'
,
{
title
:
'
Express
'
});
res
.
render
(
'index'
,
{
title
:
'
KindOfYourDog
'
});
});
router
.
post
(
'/upload'
,
function
(
req
,
res
,
next
)
{
var
name
=
""
})
module
.
exports
=
router
;
...
...
Please
register
or
login
to post a comment