From 0bb983c2fe54545ba6263aeddaf69dcf78666fb2 Mon Sep 17 00:00:00 2001 From: Fabricio Silva Date: Thu, 02 Jan 2025 01:08:03 +0000 Subject: [PATCH] fix relative paths for static and views --- .env.example | 2 +- server.js | 8 +++++--- src/constants.js | 2 -- 3 file(s) changed, 6 insertion(s)(+), 6 deletion(s)(-) diff --git a/.env.example b/.env.example --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ PORT=3000 # port to listen to BIND=127.0.0.1 # interface to bind the port BASE_URL=http://localhost:3000 # reverse proxy (url users see) -DB_PATH=./gists.db # database file, if inside a folder it needs to exists, if empty runs in memory +DB_PATH=gists.db # database file, if inside a folder it needs to exists, if empty runs in memory diff --git a/server.js b/server.js --- a/server.js +++ b/server.js @@ -1,22 +1,24 @@ +#!/usr/bin/env node import Koa from "koa"; import serve from "koa-static"; import render from "@koa/ejs"; import { bodyParser } from "@koa/bodyparser"; import { router } from "./src/routes.js"; -import { IS_PROD, BIND, PORT, LIMIT_SIZE } from "./src/constants.js"; +import { BIND, PORT, LIMIT_SIZE } from "./src/constants.js"; const app = new Koa(); +const { dirname } = import.meta; // static server app.use( - serve(IS_PROD ? "./static/dist" : "./static", { + serve(`${dirname}/static`, { maxAge: 2592000 * 1000, // 30d in milliseconds }) ); // views render(app, { - root: "./src/views", + root: `${dirname}/src/views`, layout: "_layout", }); diff --git a/src/constants.js b/src/constants.js --- a/src/constants.js +++ b/src/constants.js @@ -3,7 +3,5 @@ export const BIND = process.env.BIND; export const BASE_URL = process.env.BASE_URL; export const DB_PATH = process.env.DB_PATH; -export const IS_PROD = process.env.NODE_ENV?.startsWith("prod"); - // upload limit size (byte) export const LIMIT_SIZE = 20_000_000; // around 20mb -- tangled.sh