mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-06 05:15:35 -06:00
Configure nixpacks to use Caddy
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path="../.env")
|
||||||
|
|
||||||
|
print(os.environ.get("ENVIRONMENT"))
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -19,7 +25,7 @@ app.add_middleware(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/api/test")
|
||||||
async def get_current_time(request: Request):
|
async def get_current_time(request: Request):
|
||||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|||||||
36
frontend/Caddyfile
Normal file
36
frontend/Caddyfile
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
# global options
|
||||||
|
admin off # theres no need for the admin api in railway's environment
|
||||||
|
persist_config off # storage isn't persistent anyway
|
||||||
|
auto_https off # railway handles https for us, this would cause issues if left enabled
|
||||||
|
log {
|
||||||
|
# runtime logs
|
||||||
|
format json # set runtime log format to json mode
|
||||||
|
}
|
||||||
|
servers {
|
||||||
|
# server options
|
||||||
|
trusted_proxies static private_ranges 100.0.0.0/8 # trust railway's proxy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# site block, listens on the $PORT environment variable, automatically assigned by railway
|
||||||
|
:{$PORT} {
|
||||||
|
respond /health 200
|
||||||
|
encode gzip
|
||||||
|
|
||||||
|
log {
|
||||||
|
# access logs
|
||||||
|
format json # set access log format to json mode
|
||||||
|
}
|
||||||
|
|
||||||
|
handle /api/* {
|
||||||
|
reverse_proxy {$BACKEND_URL} # reverse proxy to the backend
|
||||||
|
}
|
||||||
|
|
||||||
|
handle {
|
||||||
|
root * dist
|
||||||
|
file_server
|
||||||
|
# if path doesn't exist, redirect it to 'index.html' for client side routing
|
||||||
|
try_files {path} /index.html
|
||||||
|
}
|
||||||
|
}
|
||||||
21
frontend/nixpacks.toml
Normal file
21
frontend/nixpacks.toml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# https://nixpacks.com/docs/configuration/file
|
||||||
|
|
||||||
|
# set up some variables to minimize annoyance
|
||||||
|
[variables]
|
||||||
|
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
|
||||||
|
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
|
||||||
|
|
||||||
|
# download caddy from nix
|
||||||
|
[phases.caddy]
|
||||||
|
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
|
||||||
|
nixpkgsArchive = 'ba913eda2df8eb72147259189d55932012df6301' # Caddy v2.8.4 - https://github.com/NixOS/nixpkgs/commit/ba913eda2df8eb72147259189d55932012df6301
|
||||||
|
nixPkgs = ['caddy'] # install caddy as a nix package
|
||||||
|
|
||||||
|
# format the Caddyfile with fmt
|
||||||
|
[phases.fmt]
|
||||||
|
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
|
||||||
|
cmds = ['caddy fmt --overwrite Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies
|
||||||
|
|
||||||
|
# start the caddy web server
|
||||||
|
[start]
|
||||||
|
cmd = 'exec caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
|
||||||
Reference in New Issue
Block a user