Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some custom url changes #10

Merged
merged 6 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export default {
region: "us-east-1",
};
},
stacks(app) {
stacks(app: App) {
if (app.stage !== 'prod') {
app.setDefaultRemovalPolicy('destroy');
}

app
.stack(BackendStack, { stackName: `${app.name}-${app.stage}-backend` })
.stack(FrontendStack, { stackName: `${app.name}-${app.stage}-frontend` });
Expand Down
24 changes: 21 additions & 3 deletions stacks/frontend.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { StackContext, StaticSite } from "sst/constructs";

export function FrontendStack({ stack }: StackContext) {
export function FrontendStack({ app, stack }: StackContext) {
const apiUrl = process.env.API_URL as string; // Ensure API_URL is treated as a string

let domainName: string;
let domainAlias: string | undefined;
if (app.stage === "prod") {
domainName = "zotnfound.com";
domainAlias = "www.zotnfound.com";
} else if (app.stage === "dev") {
domainName = "dev.zotnfound.com";
} else if (app.stage.match(/^staging-(\d+)$/)) {
// check if stage is like staging-###
domainName = `${app.stage}.zotnfound.com`;
} else {
throw new Error("Invalid stage");
}

const web = new StaticSite(stack, "web", {
path: "packages/web",
buildOutput: "dist",
buildCommand: "pnpm run build",
customDomain: "zotnfound.com",
customDomain: {
domainName: domainName,
domainAlias: domainAlias,
hostedZone: "zotnfound.com",
},
environment: {
VITE_REACT_APP_AWS_BACKEND_URL: apiUrl, //https://805cgohzr0.execute-api.us-east-1.amazonaws.com/
VITE_REACT_APP_API_KEY: process.env.VITE_REACT_APP_API_KEY!,
Expand All @@ -20,7 +38,7 @@ export function FrontendStack({ stack }: StackContext) {
VITE_REACT_APP_MEASUREMENT_ID: process.env.VITE_REACT_APP_MEASUREMENT_ID!,
},
});

stack.addOutputs({
WebEndpoint: web.customDomainUrl,
});
Expand Down