aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/app.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-08-12 15:37:30 +0200
committerHampusM <hampus@hampusmat.com>2021-08-12 15:37:30 +0200
commitd41b27f43335cfb1a8ff49aeb121f992332429cf (patch)
tree93b6e1ec9b292c3d80ee1a538d0e729612148052 /packages/server/src/app.ts
parent30f0b2ee1f494be1786280040fb47ec18bde8a6d (diff)
Cleaned up the settings implementation & renamed base_dir project-wide to git_dir
Diffstat (limited to 'packages/server/src/app.ts')
-rw-r--r--packages/server/src/app.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts
index f52333c..9ca3769 100644
--- a/packages/server/src/app.ts
+++ b/packages/server/src/app.ts
@@ -3,8 +3,11 @@ import { fastify as fastifyFactory, FastifyInstance } from "fastify";
import fastifyStatic from "fastify-static";
import { Settings } from "./types";
import repo from "./routes/repo";
+import { join } from "path";
+import { readdirSync } from "fs";
+import { exit } from "process";
-export default function buildApp(settings: Settings, dist_dir: string): FastifyInstance {
+export default function buildApp(settings: Settings): FastifyInstance {
const fastify = fastifyFactory();
fastify.setErrorHandler((err, req, reply) => {
@@ -16,7 +19,17 @@ export default function buildApp(settings: Settings, dist_dir: string): FastifyI
reply.code(404).send("Page not found!");
});
- if(settings.production) {
+ if(!settings.dev) {
+ const dist_dir = join(__dirname, "/../../client/dist");
+
+ try {
+ readdirSync(dist_dir);
+ }
+ catch {
+ console.error("Error: Client dist directory doesn't exist!");
+ exit(1);
+ }
+
fastify.register(fastifyStatic, { root: dist_dir });
fastify.route({