mirror of
https://github.com/gabehf/cloudcomputing-project.git
synced 2026-03-07 21:48:16 -08:00
removed api gateway
This commit is contained in:
parent
61a047f198
commit
1ce9243f72
2 changed files with 44 additions and 125 deletions
53
src/index.js
53
src/index.js
|
|
@ -8,16 +8,39 @@ const params = {
|
|||
}
|
||||
|
||||
exports.handler = async (e, ctx) => {
|
||||
let scan = await docClient.scan(params).promise()
|
||||
let data = {
|
||||
songs: []
|
||||
}
|
||||
do {
|
||||
scan.Items.forEach((i) => data.songs.push(i))
|
||||
params.ExclusiveStartKey = scan.LastEvaluatedKey
|
||||
} while (typeof scan.LastEvaluatedKey != 'undefined')
|
||||
console.log(e)
|
||||
return response(sqrl.render(template, data))
|
||||
if (e.requestContext.http.method == "POST" && e.requestContext.http.path == "/add") {
|
||||
// handle POST /add
|
||||
let data = JSON.parse(e.body) // body content sent as JSON
|
||||
docClient.put({
|
||||
TableName: 'MusicTable',
|
||||
Item: {
|
||||
id: `${data.Title}-${data.Artist}`,
|
||||
Title: data.Title,
|
||||
Artist: data.Artist,
|
||||
File: 'notyetimplemented.mp3'
|
||||
}
|
||||
}, (err, d) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
console.log(d)
|
||||
}
|
||||
})
|
||||
return JSON.stringify({
|
||||
success: true
|
||||
})
|
||||
} else {
|
||||
let scan = await docClient.scan(params).promise()
|
||||
let data = {
|
||||
songs: []
|
||||
}
|
||||
do {
|
||||
scan.Items.forEach((i) => data.songs.push(i))
|
||||
params.ExclusiveStartKey = scan.LastEvaluatedKey
|
||||
} while (typeof scan.LastEvaluatedKey != 'undefined')
|
||||
return response(sqrl.render(template, data))
|
||||
}
|
||||
}
|
||||
|
||||
function response(html){
|
||||
|
|
@ -42,14 +65,14 @@ const template = `
|
|||
<body>
|
||||
<div class="content">
|
||||
<h1>Illegal Music Site</h1>
|
||||
<form onSubmit="formSubmit()" name="addForm">
|
||||
<form id="addSongForm">
|
||||
<label for="Title">Title</label>
|
||||
<input type="text" id="Title" name="Title" placeholder="Title" />
|
||||
<label for="Artist">Artist</label>
|
||||
<input type="text" id="Artist" name="Artist" placeholder="Artist" />
|
||||
<label for="File">File</label>
|
||||
<input type="File" id="File" name="File"/>
|
||||
<input type="submit"/>
|
||||
<button id="formSubmit">Submit</button>
|
||||
</form>
|
||||
<div>
|
||||
{{@each(it.songs) => s, i}}
|
||||
|
|
@ -63,7 +86,9 @@ const template = `
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
async function formSubmit() {
|
||||
document.getElementById("formSubmit").addEventListener("click", formSubmit)
|
||||
async function formSubmit(e) {
|
||||
e.preventDefault()
|
||||
let title = document.getElementById("Title").value
|
||||
let artist = document.getElementById("Artist").value
|
||||
|
||||
|
|
@ -74,6 +99,10 @@ const template = `
|
|||
Title: title
|
||||
})
|
||||
})
|
||||
// console.log({
|
||||
// Artist: artist,
|
||||
// Title: title
|
||||
// })
|
||||
window.location.reload()
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
116
template.yml
116
template.yml
|
|
@ -65,55 +65,6 @@ Metadata:
|
|||
embeds: []
|
||||
isassociatedwith:
|
||||
- 80500ba5-1749-47bc-8cfa-3e9a0f0d0572
|
||||
d701293c-6494-4f90-b758-31f57f52e379:
|
||||
size:
|
||||
width: 60
|
||||
height: 60
|
||||
position:
|
||||
x: -190
|
||||
'y': 250
|
||||
z: 0
|
||||
embeds: []
|
||||
7d399dae-9f6c-4026-9286-d33113777902:
|
||||
size:
|
||||
width: 60
|
||||
height: 60
|
||||
position:
|
||||
x: -360
|
||||
'y': 250
|
||||
z: 0
|
||||
embeds: []
|
||||
b27ea063-d0ac-40c1-8c49-9147a53ea072:
|
||||
size:
|
||||
width: 60
|
||||
height: 60
|
||||
position:
|
||||
x: -270
|
||||
'y': 380
|
||||
z: 0
|
||||
embeds: []
|
||||
88fe53b7-5e96-416e-ad00-9ebe8d04269a:
|
||||
size:
|
||||
width: 60
|
||||
height: 60
|
||||
position:
|
||||
x: -200
|
||||
'y': 140
|
||||
z: 0
|
||||
embeds: []
|
||||
dependson:
|
||||
- 80500ba5-1749-47bc-8cfa-3e9a0f0d0572
|
||||
badaa010-8776-4159-8720-9ee8be16806e:
|
||||
size:
|
||||
width: 60
|
||||
height: 60
|
||||
position:
|
||||
x: 80
|
||||
'y': 380
|
||||
z: 0
|
||||
embeds: []
|
||||
isassociatedwith:
|
||||
- 80500ba5-1749-47bc-8cfa-3e9a0f0d0572
|
||||
Resources:
|
||||
URL:
|
||||
Type: 'AWS::Lambda::Url'
|
||||
|
|
@ -134,7 +85,7 @@ Resources:
|
|||
Handler: index.handler
|
||||
Runtime: nodejs16.x
|
||||
Code:
|
||||
S3Bucket: '${bucketname}'
|
||||
S3Bucket: ${bucketname}
|
||||
S3Key: index.zip
|
||||
Role: !GetAtt SiteRole.Arn
|
||||
Metadata:
|
||||
|
|
@ -197,70 +148,9 @@ Resources:
|
|||
Type: 'AWS::Lambda::Permission'
|
||||
Properties:
|
||||
Action: 'lambda:invokeFunctionUrl'
|
||||
FunctionUrlAuthType: NONE
|
||||
FunctionUrlAuthType: 'NONE'
|
||||
FunctionName: !Ref Server
|
||||
Principal: '*'
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: 161bd476-b869-4c2e-968b-05cd0b73052f
|
||||
MusicAPI:
|
||||
Type: 'AWS::ApiGatewayV2::Api'
|
||||
Properties:
|
||||
Target: !GetAtt Server.Arn
|
||||
Name: MusicAPI
|
||||
ProtocolType: HTTP
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: d701293c-6494-4f90-b758-31f57f52e379
|
||||
HomeRoute:
|
||||
Type: 'AWS::ApiGatewayV2::Route'
|
||||
Properties:
|
||||
ApiId: !Ref MusicAPI
|
||||
RouteKey: Get /
|
||||
Target: !Join
|
||||
- /
|
||||
- - integrations
|
||||
- !Ref APIIntegration
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: 7d399dae-9f6c-4026-9286-d33113777902
|
||||
DependsOn:
|
||||
- MusicAPI
|
||||
AddRoute:
|
||||
Type: 'AWS::ApiGatewayV2::Route'
|
||||
Properties:
|
||||
ApiId: !Ref MusicAPI
|
||||
RouteKey: POST /add
|
||||
Target: !Join
|
||||
- /
|
||||
- - integrations
|
||||
- !Ref APIIntegration
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: b27ea063-d0ac-40c1-8c49-9147a53ea072
|
||||
DependsOn:
|
||||
- MusicAPI
|
||||
APIIntegration:
|
||||
Type: 'AWS::ApiGatewayV2::Integration'
|
||||
Properties:
|
||||
ApiId: !Ref MusicAPI
|
||||
IntegrationType: AWS_PROXY
|
||||
PayloadFormatVersion: 2.0
|
||||
IntegrationUri:
|
||||
'Fn::Sub': >-
|
||||
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Server.Arn}/invocations
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: 88fe53b7-5e96-416e-ad00-9ebe8d04269a
|
||||
DependsOn:
|
||||
- Server
|
||||
APIPermission:
|
||||
Type: 'AWS::Lambda::Permission'
|
||||
Properties:
|
||||
Action: 'lambda:InvokeFunction'
|
||||
FunctionName: !Ref Server
|
||||
Principal: apigateway.amazonaws.com
|
||||
SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MusicAPI}/*/*/'
|
||||
Metadata:
|
||||
'AWS::CloudFormation::Designer':
|
||||
id: badaa010-8776-4159-8720-9ee8be16806e
|
||||
id: 161bd476-b869-4c2e-968b-05cd0b73052f
|
||||
Loading…
Add table
Add a link
Reference in a new issue