Skip to content

Commit 5a8adc4

Browse files
committed
Setup static site
1 parent bc75d2d commit 5a8adc4

File tree

8 files changed

+86
-7
lines changed

8 files changed

+86
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.sst
33
.build
4+
yarn-error.log

frontend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@acme/frontend",
33
"version": "0.0.0",
44
"scripts": {
5-
"dev": "vite",
5+
"dev": "sst-env -- vite",
66
"build": "tsc && vite build",
77
"preview": "vite preview"
88
},
@@ -12,6 +12,7 @@
1212
"urql": "^2.0.6"
1313
},
1414
"devDependencies": {
15+
"@serverless-stack/static-site-env": "^0.56.2",
1516
"@types/react": "^17.0.33",
1617
"@types/react-dom": "^17.0.10",
1718
"@vitejs/plugin-react": "^1.0.7",

frontend/src/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const Config = {
2+
APOLLO_URL: import.meta.env.VITE_APOLLO_URL as string,
3+
};
4+
console.log("Config", Config);

frontend/src/main.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import ReactDOM from "react-dom";
33

44
import { Todos } from "./pages/Todos";
55
import * as urql from "urql";
6+
import { Config } from "./config";
67

78
const client = urql.createClient({
8-
url: "https://d7nn8pnx3g.execute-api.us-east-2.amazonaws.com",
9+
url: Config.APOLLO_URL,
910
});
1011

1112
ReactDOM.render(

stacks/Api.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import * as sst from "@serverless-stack/resources";
22

33
export class Api extends sst.Stack {
4+
public readonly outputs: {
5+
apollo: string;
6+
};
7+
48
constructor(scope: sst.App) {
5-
super(scope, "gql");
9+
super(scope, "api");
610

711
const apollo = new sst.ApolloApi(this, "apollo", {
812
server: "services/apollo/apollo.handler",
913
});
1014

11-
this.addOutputs({
12-
Apollo: apollo.url,
13-
});
15+
this.outputs = {
16+
apollo: apollo.url,
17+
};
1418
}
1519
}

stacks/Frontend.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as sst from "@serverless-stack/resources";
2+
import { Api } from "./Api";
3+
4+
type Props = {
5+
api: Api["outputs"];
6+
};
7+
8+
export class Frontend extends sst.Stack {
9+
constructor(scope: sst.App, props: Props) {
10+
super(scope, "frontend");
11+
12+
const site = new sst.StaticSite(this, "frontend", {
13+
path: "frontend",
14+
environment: {
15+
VITE_APOLLO_URL: props.api.apollo,
16+
},
17+
});
18+
19+
this.addOutputs({
20+
Site: site.url,
21+
});
22+
}
23+
}

stacks/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as sst from "@serverless-stack/resources";
22
import { Api } from "./Api";
3+
import { Frontend } from "./Frontend";
34

45
export default function main(app: sst.App): void {
56
app.setDefaultFunctionProps({
@@ -8,5 +9,8 @@ export default function main(app: sst.App): void {
89
environment: {},
910
});
1011

11-
new Api(app);
12+
const api = new Api(app);
13+
new Frontend(app, {
14+
api: api.outputs,
15+
});
1216
}

yarn.lock

+41
Original file line numberDiff line numberDiff line change
@@ -5176,6 +5176,38 @@
51765176
xstate "^4.26.1"
51775177
zod "^3.11.6"
51785178

5179+
"@serverless-stack/core@^0.56.2":
5180+
version "0.56.2"
5181+
resolved "https://registry.yarnpkg.com/@serverless-stack/core/-/core-0.56.2.tgz#a552aa12345055eec84ddaff1da595aa8b601108"
5182+
integrity sha512-67n9vGOn9KIHCXDED3E5eUKfFgOyejisaA3Iy0+7ybI9sdDFN49rrj/F/SQWm0YlnfDD7wak0l4CaMa1iBD/fw==
5183+
dependencies:
5184+
"@aws-sdk/client-s3" "^3.45.0"
5185+
"@trpc/client" "^9.16.0"
5186+
"@trpc/react" "^9.16.0"
5187+
"@trpc/server" "^9.16.0"
5188+
"@types/picomatch" "^2.3.0"
5189+
aws-cdk "1.132.0"
5190+
aws-sdk "^2.761.0"
5191+
chalk "^4.1.0"
5192+
chokidar "^3.5.2"
5193+
cross-spawn "^7.0.3"
5194+
dataloader "^2.0.0"
5195+
dendriform-immer-patch-optimiser "^2.1.0"
5196+
dotenv "^10.0.0"
5197+
dotenv-expand "^5.1.0"
5198+
express "^4.17.1"
5199+
fs-extra "^9.0.1"
5200+
immer "^9.0.7"
5201+
js-yaml "^4.1.0"
5202+
log4js "^6.3.0"
5203+
picomatch "^2.3.0"
5204+
remeda "^0.0.32"
5205+
stun "^2.1.0"
5206+
typescript "^4.4.3"
5207+
uuid "^8.3.2"
5208+
xstate "^4.26.1"
5209+
zod "^3.11.6"
5210+
51795211
"@serverless-stack/nextjs-core@^0.1.9":
51805212
version "0.1.9"
51815213
resolved "https://registry.yarnpkg.com/@serverless-stack/nextjs-core/-/nextjs-core-0.1.9.tgz#ca480e8081df5d262ed5f61ef44584e130198e17"
@@ -5268,6 +5300,15 @@
52685300
typescript "^4.4.3"
52695301
zip-local "^0.3.4"
52705302

5303+
"@serverless-stack/static-site-env@^0.56.2":
5304+
version "0.56.2"
5305+
resolved "https://registry.yarnpkg.com/@serverless-stack/static-site-env/-/static-site-env-0.56.2.tgz#4c972dc717722671c2a2b1d8ba32f4c950b37876"
5306+
integrity sha512-SJ1AXu90oEgn4aaSJJGBeBeaeokLuMLIGKiGD8/tmW/QI72YYNzJNHu/mMHFokvNwl4Uxq3gmBclP39UyUaKYA==
5307+
dependencies:
5308+
"@serverless-stack/core" "^0.56.2"
5309+
chalk "^4.1.0"
5310+
yargs "^15.4.1"
5311+
52715312
"@sindresorhus/is@^0.14.0":
52725313
version "0.14.0"
52735314
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"

0 commit comments

Comments
 (0)