diff --git a/.github/near-rewards.yml b/.github/near-rewards.yml new file mode 100644 index 0000000..16ed2b3 --- /dev/null +++ b/.github/near-rewards.yml @@ -0,0 +1,28 @@ +name: NEAR Protocol Rewards Tracking +on: + schedule: + - cron: '0 */12 * * *' # Every 12 hours + workflow_dispatch: # Manual trigger + push: + branches: [ main ] # Start on main branch updates + +jobs: + calculate-rewards: + runs-on: ubuntu-latest + permissions: + contents: read + issues: read + pull-requests: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Calculate Rewards + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO: ${{ github.repository }} + run: | + npm install -g near-protocol-rewards@latest + near-protocol-rewards calculate \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 548ed24..106ce23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ WORKDIR /app # Copy backend package files COPY package.json ./ COPY backend/package.json ./backend/ +COPY backend/drizzle.config.ts ./backend/ # Install backend dependencies RUN cd backend && bun install @@ -57,11 +58,14 @@ COPY --from=backend-builder --chown=bun:bun /app/package.json ./ COPY --chown=bun:bun curate.config.json ./ COPY --from=frontend-builder --chown=bun:bun /app/frontend/dist ./frontend/dist -COPY --from=backend-builder --chown=bun:bun /app/backend/dist ./backend/dist +COPY --from=backend-builder --chown=bun:bun /app/backend ./backend + +RUN cd backend && bun install # Set environment variables ENV DATABASE_URL="file:/litefs/db" ENV NODE_ENV="production" +ENV FRONTEND_DIST_PATH="/app/frontend/dist" # Expose the port EXPOSE 3000 diff --git a/backend/package.json b/backend/package.json index dfb72bc..b9315a4 100644 --- a/backend/package.json +++ b/backend/package.json @@ -41,6 +41,7 @@ }, "dependencies": { "@elysiajs/cors": "^1.2.0", + "@elysiajs/static": "^1.2.0", "@elysiajs/swagger": "^1.2.0", "@libsql/client": "^0.14.0", "@types/cors": "^2.8.17", diff --git a/backend/src/index.ts b/backend/src/index.ts index 3d905ea..19e621a 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -3,6 +3,7 @@ import path from "path"; import { Elysia } from "elysia"; import { cors } from "@elysiajs/cors"; import { swagger } from "@elysiajs/swagger"; +import { staticPlugin } from "@elysiajs/static"; import { DistributionService } from "services/distribution/distribution.service"; import configService, { validateEnv } from "./config/config"; import { db } from "./services/db"; @@ -210,23 +211,28 @@ export async function main() { return { processed }; }) - // Static file serving in production - .get("/*", async ({ request }) => { - if (process.env.NODE_ENV === "production") { - const url = new URL(request.url); - const filePath = url.pathname === "/" ? "/index.html" : url.pathname; - const file = Bun.file( - path.join(__dirname, "../../frontend/dist", filePath), - ); - if (await file.exists()) { - return new Response(file); - } - // Fallback to index.html for client-side routing - return new Response( - Bun.file(path.join(__dirname, "../../frontend/dist/index.html")), - ); - } - throw new Error("Not found"); + // Serve static files in production + .use( + staticPlugin({ + assets: + process.env.FRONTEND_DIST_PATH || + path.join(process.cwd(), "../frontend/dist"), + prefix: "/", + indexHTML: true, // Enable SPA routing + }), + ) + .get("/debug/env", () => { + return { + cwd: process.cwd(), + frontendPath: + process.env.FRONTEND_DIST_PATH || + path.join(process.cwd(), "../frontend/dist"), + resolvedPath: path.resolve( + process.env.FRONTEND_DIST_PATH || + path.join(process.cwd(), "../frontend/dist"), + ), + env: process.env.NODE_ENV, + }; }) .onError(({ error }) => { logger.error("Request error:", error); diff --git a/bun.lockb b/bun.lockb index 367fd44..025dc46 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/fly.toml b/fly.toml index 3056e29..efaa1e7 100644 --- a/fly.toml +++ b/fly.toml @@ -29,4 +29,3 @@ primary_region = 'den' memory = '1gb' cpu_kind = 'shared' cpus = 1 - \ No newline at end of file diff --git a/litefs.yml b/litefs.yml index 26bac5d..f2fc7c6 100644 --- a/litefs.yml +++ b/litefs.yml @@ -33,6 +33,7 @@ proxy: # the last command to be long-running (e.g. an application server). When the # last command exits, LiteFS is shut down. exec: + - cmd: "bun run db:push" - cmd: "bun run start" # The lease section specifies how the cluster will be managed. We're using the diff --git a/package.json b/package.json index ebc7f57..b7c47f4 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dev": "bunx turbo run dev", "build": "bunx turbo run build", "start": "NODE_ENV=production cd backend && bun run dist/index.js", + "db:push": "cd backend && bun run db:push", "lint": "bunx turbo run lint", "deploy:init": "fly launch && fly consul attach", "deploy": "fly deploy",