Skip to content
Open
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ The server that stores all the encrypted sharable drawings from [Excalidraw](htt

Get the [`service key`](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) as JSON and store it under `keys` directory with the name of the project ID.

### Environment Variables

| Variable | Description | Default Value | Required |
| -------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------- | -------- |
| `GOOGLE_CLOUD_PROJECT` | Google Cloud project ID | `excalidraw-json-dev` | No |
| `GOOGLE_CLOUD_BUCKET_NAME` | Google Cloud Storage bucket name | `excalidraw-json.appspot.com` (prod) or `excalidraw-json-dev.appspot.com` (dev) | No |
| `NODE_ENV` | Environment mode | - | No |
| `ALLOW_ORIGINS` | Comma-separated list of allowed origins for CORS | Default allowed origins list | No |
| `PORT` | Port number for the server | `8080` | No |

### Commands

```
Expand Down
29 changes: 19 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as path from "path";
const PROJECT_NAME = process.env.GOOGLE_CLOUD_PROJECT || "excalidraw-json-dev";
const PROD = PROJECT_NAME === "excalidraw-json";
const LOCAL = process.env.NODE_ENV !== "production";
const BUCKET_NAME = PROD
? "excalidraw-json.appspot.com"
: "excalidraw-json-dev.appspot.com";
const BUCKET_NAME =
process.env.GOOGLE_CLOUD_BUCKET_NAME ||
(PROD ? "excalidraw-json.appspot.com" : "excalidraw-json-dev.appspot.com");

const FILE_SIZE_LIMIT = 2 * 1024 * 1024;
const storage = new Storage(
Expand All @@ -25,13 +25,22 @@ const storage = new Storage(
const bucket = storage.bucket(BUCKET_NAME);
const app = express();

let allowOrigins = [
"excalidraw.vercel.app",
"https://dai-shi.github.io",
"https://excalidraw.com",
"https://www.excalidraw.com",
"https://math.preview.excalidraw.com",
];
let allowOrigins: string[] = [];

if (process.env.ALLOW_ORIGINS) {
allowOrigins = process.env.ALLOW_ORIGINS.split(",").map((origin) =>
origin.trim()
);
} else {
allowOrigins = [
"excalidraw.vercel.app",
"https://dai-shi.github.io",
"https://excalidraw.com",
"https://www.excalidraw.com",
"https://math.preview.excalidraw.com",
];
}

if (!PROD) {
allowOrigins.push("http://localhost:");
}
Expand Down