Skip to content

Commit

Permalink
Merge pull request #23 from nyaomaru/fix-environment-setting
Browse files Browse the repository at this point in the history
fix: environment setting
  • Loading branch information
nyaomaru authored Sep 7, 2024
2 parents 694dff5 + 6b659b1 commit 44f80e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
"manifest": "deno task cli manifest $(pwd)",
"start": "deno run -A --watch=src/static/,src/routes/ --unstable src/dev.ts",
"start": "DENO_ENV=development deno run -A --watch=src/static/,src/routes/ --unstable src/dev.ts",
"build": "deno run -A --unstable src/dev.ts build",
"preview": "deno run -A --unstable src/main.ts",
"update": "deno run -A -r https://fresh.deno.dev/update .",
Expand Down
19 changes: 16 additions & 3 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ export default function Home({ data }: PageProps<string>) {
if (!csp.directives.scriptSrc) {
csp.directives.scriptSrc = [];
}
csp.directives.styleSrc.push("http://localhost:8000/styles.css");
csp.directives.imgSrc.push("http://localhost:8000/logo.svg");
csp.directives.scriptSrc.push("http://localhost:8000");
const baseUrl = Deno.env.get("DENO_ENV") === "development"
? "http://localhost:8000"
: "https://nyaomaru-deno-sample.deno.dev";

csp.directives.styleSrc.push(`${baseUrl}/styles.css`);
csp.directives.imgSrc.push(`${baseUrl}/logo.svg`);
csp.directives.scriptSrc.push(baseUrl);

if (Deno.env.get("DENO_ENV") !== "production") {
const previewUrl = `https://nyaomaru-deno-sample-${
Deno.env.get("DENO_DEPLOYMENT_ID")
}.deno.dev`;
csp.directives.styleSrc.push(`${previewUrl}/styles.css`);
csp.directives.imgSrc.push(`${previewUrl}/logo.svg`);
csp.directives.scriptSrc.push(previewUrl);
}
});

return (
Expand Down

0 comments on commit 44f80e4

Please sign in to comment.