summary refs log tree commit diff
path: root/src/start.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/start.ts')
-rw-r--r--src/start.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/start.ts b/src/start.ts
index 822a749f..57c9f704 100644
--- a/src/start.ts
+++ b/src/start.ts
@@ -1,17 +1,23 @@
+import path from "path";
 import dotenv from "dotenv";
+import fse from "fs-extra";
 dotenv.config();
 
-import { CDNServer } from "./Server";
-
-if (process.env.STORAGE_LOCATION) {
-	if (!process.env.STORAGE_LOCATION.startsWith("/")) {
-		process.env.STORAGE_LOCATION = __dirname + "/../" + process.env.STORAGE_LOCATION;
+if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
+// TODO:nodejs path.join trailing slash windows compatible
+if (process.env.STORAGE_PROVIDER === "file") {
+	if (process.env.STORAGE_LOCATION) {
+		if (!process.env.STORAGE_LOCATION.startsWith("/")) {
+			process.env.STORAGE_LOCATION = path.join(__dirname, "..", process.env.STORAGE_LOCATION, "/");
+		}
+	} else {
+		process.env.STORAGE_LOCATION = path.join(__dirname, "..", "files", "/");
 	}
-} else {
-	process.env.STORAGE_LOCATION = __dirname + "/../files/";
-	process.env.STORAGE_PROVIDER = "file";
+	fse.ensureDirSync(process.env.STORAGE_LOCATION);
 }
 
+import { CDNServer } from "./Server";
+
 const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
 server
 	.start()