summary refs log tree commit diff
path: root/src/start.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 20:16:17 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 20:16:17 +0200
commit87c7cf33d036c9ef1486d5d895f2b9a6b94bf045 (patch)
tree4bec620a49cd29b10b28f3596176f5f6a344cffd /src/start.ts
parent:sparkles: api (diff)
parentcatch for missing config error (diff)
downloadserver-87c7cf33d036c9ef1486d5d895f2b9a6b94bf045.tar.xz
Merge branch 'cdn'
Diffstat (limited to 'src/start.ts')
-rw-r--r--src/start.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/start.ts b/src/start.ts
new file mode 100644

index 00000000..57c9f704 --- /dev/null +++ b/src/start.ts
@@ -0,0 +1,27 @@ +import path from "path"; +import dotenv from "dotenv"; +import fse from "fs-extra"; +dotenv.config(); + +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", "/"); + } + fse.ensureDirSync(process.env.STORAGE_LOCATION); +} + +import { CDNServer } from "./Server"; + +const server = new CDNServer({ port: Number(process.env.PORT) || 3003 }); +server + .start() + .then(() => { + console.log("[Server] started on :" + server.options.port); + }) + .catch((e) => console.error("[Server] Error starting: ", e));