gromer

#golang#htmx#ssr

git clone https://git.pyrossh.dev/gromer

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


1d4b2d2pyros2097 2020-12-19T16:37:02+05:30
fix dns records
example/.gitignore CHANGED
@@ -19,5 +19,3 @@ test
19
19
  *.gcloudignore
20
20
  *.wasm
21
21
  main
22
- build
23
- vendor
example/makefile CHANGED
@@ -1,17 +1,22 @@
1
1
  run:
2
2
  go run *.go
3
3
 
4
- go:
5
- go build
4
+ wasm: export GOOS=js
6
-
5
+ wasm: export GOARCH=wasm
7
6
  wasm:
8
- GOOS=js GOARCH=wasm go build -o assets/main.wasm
7
+ go build -o assets/main.wasm
9
8
 
10
9
  css:
11
10
  npx tailwindcss-cli@latest build assets/config.css -o assets/styles.css
12
11
 
12
+ deploy: export NODE_ENV=production
13
+ deploy:
14
+ npx tailwindcss-cli@latest build assets/config.css -o assets/styles.css
15
+ go build -o main
16
+ make wasm
13
- lambda:
17
+ sam deploy
14
- sam local start-api
18
+ aws s3 sync ./assets s3://wapp.pyros2097.dev/assets --delete
19
+ aws cloudfront create-invalidation --distribution-id E17XVZYYZ1JXEU --paths "/*"
15
20
 
16
- sync:
21
+ local:
17
- aws s3 sync ./assets --delete public --dryrun s3://go-app-bucket-111
22
+ sam local start-api
example/samconfig.toml CHANGED
@@ -2,8 +2,9 @@ version = 0.1
2
2
  [default]
3
3
  [default.deploy]
4
4
  [default.deploy.parameters]
5
- stack_name = "go-app"
5
+ stack_name = "wapp-pyros2097-dev"
6
6
  s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-grb3hle00qk9"
7
- s3_prefix = "go-app"
7
+ s3_prefix = "wapp-pyros2097-dev"
8
8
  region = "us-east-1"
9
9
  capabilities = "CAPABILITY_IAM"
10
+ parameter_overrides = "DomainName=\"wapp.pyros2097.dev\" HostedZoneId=\"Z0469276792OXT6RNZF5\" AcmCertificateArn=\"arn:aws:acm:us-east-1:719747015987:certificate/16acd03e-b59a-459c-8a3f-5caa50df7079\""
example/tailwind.config.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ purge: {
3
+ content: [
4
+ './*.go',
5
+ ],
6
+ options: {
7
+ safelist: ['flex', 'flex-row', 'justify-center', 'items-center'],
8
+ }
9
+ },
10
+ theme: {},
11
+ variants: {},
12
+ plugins: [],
13
+ }
example/template.yml CHANGED
@@ -1,51 +1,135 @@
1
+ ---
1
- AWSTemplateFormatVersion: 2010-09-09
2
+ AWSTemplateFormatVersion: "2010-09-09"
3
+ Transform: AWS::Serverless-2016-10-31
4
+ Parameters:
5
+ DomainName:
6
+ Type: String
7
+ Default: wapp.pyros2097.dev
8
+ HostedZoneId:
9
+ Type: String
10
+ Default: Z0469276792OXT6RNZF5
11
+ AcmCertificateArn:
12
+ Type: String
13
+ Default: arn:aws:acm:us-east-1:719747015987:certificate/16acd03e-b59a-459c-8a3f-5caa50df7079
14
+
2
15
  Outputs:
16
+ DistributionId:
17
+ Value: !Ref CloudFrontDistribution
18
+ DistributionDomain:
19
+ Value: !GetAtt CloudFrontDistribution.DomainName
3
20
  ApiUrl:
4
- Value:
5
- Fn::Sub: https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/Prod/
21
+ Value: !Sub https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/Prod/
22
+
6
23
  Resources:
7
- GoAppBucket:
24
+ WebBucket:
8
25
  Type: AWS::S3::Bucket
9
26
  Properties:
10
- BucketName: go-app-bucket-111
27
+ BucketName: !Ref DomainName
11
- AccessControl: Private
28
+
12
- PublicAccessBlockConfiguration:
13
- BlockPublicAcls: false
14
- BlockPublicPolicy: false
15
- IgnorePublicAcls: false
16
- RestrictPublicBuckets: false
29
+ CloudFrontOriginAccessIdentity:
17
- HttpApi:
30
+ Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
18
31
  Properties:
19
- AccessLogSettings:
32
+ CloudFrontOriginAccessIdentityConfig:
33
+ Comment: "CloudFront OAI"
34
+
20
- DestinationArn:
35
+ WebBucketPolicy:
36
+ Type: AWS::S3::BucketPolicy
21
- Fn::GetAtt:
37
+ Properties:
22
- - HttpApiAccessLogs
38
+ Bucket: !Ref WebBucket
23
- - Arn
24
- Format:
39
+ PolicyDocument:
25
- '{"requestId":"$context.requestId", "ip": "$context.identity.sourceIp",
26
- "caller":"$context.identity.caller", "user":"$context.identity.user", "requestTime":"$context.requestTime","routeKey":"$context.routeKey",
27
- "status":"$context.status", "error": "$context.integrationErrorMessage"}'
28
- StageName: Prod
40
+ Statement:
41
+ - Effect: Allow
42
+ Principal:
43
+ CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId
44
+ Action: s3:GetObject
45
+ Resource: !Join ["/", [!GetAtt WebBucket.Arn, "*"]]
46
+ - Effect: Allow
47
+ Principal:
48
+ CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId
49
+ Action: s3:ListBucket
50
+ Resource: !GetAtt WebBucket.Arn
51
+
52
+ HttpApi:
29
53
  Type: AWS::Serverless::HttpApi
30
- HttpApiAccessLogs:
31
54
  Properties:
32
- LogGroupName: /aws/http/py-app
55
+ StageName: Prod
56
+
33
- RetentionInDays: 365
57
+ HttpApiLambda:
34
- Type: AWS::Logs::LogGroup
58
+ Type: AWS::Serverless::Function
35
- RouteIndex:
36
59
  Properties:
60
+ Runtime: go1.x
61
+ MemorySize: 128
62
+ Timeout: 30
37
- Handler: ./example
63
+ Handler: ./main
38
64
  Events:
39
65
  ApiEvent:
66
+ Type: HttpApi
40
67
  Properties:
41
68
  ApiId:
42
69
  Ref: HttpApi
43
- Method: GET
70
+ Method: ANY
44
- Path: $default
71
+ Path: '$default'
72
+
73
+ CloudFrontDistribution:
74
+ Type: AWS::CloudFront::Distribution
75
+ Properties:
76
+ DistributionConfig:
77
+ Aliases:
78
+ - !Ref DomainName
79
+ HttpVersion: http2
80
+ Enabled: true
81
+ IPV6Enabled: true
82
+ PriceClass: PriceClass_All
83
+ Origins:
84
+ - Id: s3
85
+ DomainName: !GetAtt WebBucket.DomainName
86
+ S3OriginConfig:
87
+ OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
88
+ - Id: app
89
+ DomainName: !Sub ${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}
90
+ OriginPath: /Prod
91
+ CustomOriginConfig:
92
+ OriginProtocolPolicy: https-only
93
+ DefaultCacheBehavior:
94
+ TargetOriginId: app
95
+ AllowedMethods: [HEAD, GET]
96
+ CachedMethods: [HEAD, GET]
97
+ ViewerProtocolPolicy: https-only
98
+ Compress: true
99
+ ForwardedValues:
100
+ QueryString: true
101
+ CacheBehaviors:
102
+ - TargetOriginId: s3
45
- PayloadFormatVersion: '1.0'
103
+ PathPattern: /assets/*
104
+ AllowedMethods: [HEAD, GET]
105
+ CachedMethods: [HEAD, GET]
106
+ ViewerProtocolPolicy: https-only
107
+ Compress: true
108
+ ForwardedValues:
109
+ QueryString: false
110
+ ViewerCertificate:
111
+ AcmCertificateArn: !Ref AcmCertificateArn
112
+ MinimumProtocolVersion: TLSv1.2_2018
113
+ SslSupportMethod: sni-only
114
+
115
+ DNSRecordSet:
116
+ Type: AWS::Route53::RecordSet
117
+ Properties:
118
+ AliasTarget:
119
+ DNSName: !GetAtt CloudFrontDistribution.DomainName
120
+ EvaluateTargetHealth: false
121
+ HostedZoneId: Z2FDTNDATAQYW2 # CloudFront hosted zone ID
122
+ HostedZoneId: !Ref HostedZoneId
123
+ Name: !Ref DomainName
124
+ Type: A
125
+
126
+ DNSIPV6RecordSet:
127
+ Type: AWS::Route53::RecordSet
128
+ Properties:
129
+ AliasTarget:
130
+ DNSName: !GetAtt CloudFrontDistribution.DomainName
131
+ EvaluateTargetHealth: false
132
+ HostedZoneId: Z2FDTNDATAQYW2 # CloudFront hosted zone ID
133
+ HostedZoneId: !Ref HostedZoneId
134
+ Name: !Ref DomainName
46
- Type: HttpApi
135
+ Type: AAAA
47
- MemorySize: 128
48
- Runtime: go1.x
49
- Timeout: 30
50
- Type: AWS::Serverless::Function
51
- Transform: AWS::Serverless-2016-10-31