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