Skip to content

Commit

Permalink
Github actions to create dist in server
Browse files Browse the repository at this point in the history
  • Loading branch information
karlosvas committed Jan 12, 2025
1 parent fb18f19 commit 089124c
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 59 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Deploy to Vercel

on:
push:
branches:
- main

jobs:
deploy-frontend:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "21.2.0"

- name: Install Vercel CLI
run: npm install -g vercel@latest

- name: List files in client directory
run: ls -la ./client

- name: Link and pull Vercel project for frontend
run: |
vercel link --yes --project ${{ secrets.FRONTEND_PROJECT_ID }} --scope ${{ secrets.VERCEL_TEAM }} --token=${{ secrets.VERCEL_TOKEN }}
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
working-directory: ./client

- name: Install frontend dependencies
run: npm install
working-directory: ./client

- name: Build frontend
run: npm run build
working-directory: ./client

- name: Deploy frontend to Vercel
run: vercel --token ${{ secrets.VERCEL_TOKEN }}
working-directory: ./client

deploy-backend:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "21.2.0"

- name: Install Vercel CLI
run: npm install -g vercel@latest

- name: List files in server directory
run: ls -la ./server

- name: Link and pull Vercel project for backend
run: |
vercel link --yes --project ${{ secrets.BACKEND_PROJECT_ID }} --scope ${{ secrets.VERCEL_TEAM }} --token=${{ secrets.VERCEL_TOKEN }}
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
working-directory: ./server

- name: Install backend dependencies
run: npm install
working-directory: ./server

- name: Build backend
run: npm run build
working-directory: ./server

- name: List files in client directory
run: ls -la ./server

- name: Deploy backend to Vercel
run: vercel --token ${{ secrets.VERCEL_TOKEN }}
working-directory: ./server
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dev
dist-ssr
client/dist
*.local
dist

# Editor directories and files
.vscode/*
Expand Down
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
7 changes: 0 additions & 7 deletions client/vercel.json

This file was deleted.

18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"type": "GNU",
"url": "https://www.gnu.org/licenses/gpl-3.0.html"
}
]
],
"dependencies": {
"prettier": "^3.4.2"
}
}
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
2 changes: 1 addition & 1 deletion server/lib/resend/resend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from "dotenv";
dotenv.config();
////////////////////////////////////////////////////////////////
import { Message, NoteType, SubscriberType } from "types/types";
import { NoteType, SubscriberType } from "types/types";
import { Resend } from "resend";

// Configurar el cliente de Mandrill
Expand Down
25 changes: 0 additions & 25 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"main": "index.ts",
"scripts": {
"start": "npm run build && node dist/index.js",
"start": "node public/src/index.js",
"dev": "node --loader ts-node/esm src/index.js",
"test": "npm run build && playwright test",
"build": "tsc"
Expand Down
7 changes: 6 additions & 1 deletion server/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ readdirSync(PATH_ROUTER).forEach((file) => {
const fileClean = cleanExtension(file);
const fileExtension = path.extname(file);

if (fileClean !== "routes" && (fileExtension === ".js" || fileExtension === ".ts") && !file.endsWith(".map")) {
if (
fileClean !== "routes" &&
(fileExtension === ".js" || fileExtension === ".ts") &&
!file.endsWith(".js.map") &&
!file.endsWith(".ts.map")
) {
const modulePath = path.join(PATH_ROUTER, `${fileClean}${fileExtension}`);
const moduleURL = pathToFileURL(modulePath).href;

Expand Down
8 changes: 4 additions & 4 deletions server/index.ts → server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import dotenv from "dotenv";
dotenv.config();
///////////////////////////////////////////
import { connectDB } from "./src/mongodb/mongodb.js";
import { connectDB } from "./mongodb/mongodb.js";
import express from "express";
import cors from "cors";
import { router } from "./routes/routes.js";
import { router } from "../routes/routes.js";
import net from "net";
import admin from "./lib/firebase/firebase-config.js";
import admin from "../lib/firebase/firebase-config.js";

// Extendemos el límite para que pueda almacenar imagenes en base64
async function inicializeApp() {
Expand Down Expand Up @@ -116,6 +116,6 @@ async function inicializeApp() {
}
}

inicializeApp().catch((error) => {
export default inicializeApp().catch((error) => {
console.error("Error starting the server:", error);
});
4 changes: 2 additions & 2 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rootDir": "./" /* Specify the root folder within your source files. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
"outDir": "dist" /* Specify an output folder for all emitted files. */,
"outDir": "public" /* Specify an output folder for all emitted files. */,
"paths": {
"types/*": ["types/*"]
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
Expand All @@ -20,5 +20,5 @@
"esm": true
} /* Enable all strict type-checking options. */,
"include": ["./**/*.ts", "types"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "public"]
}
16 changes: 0 additions & 16 deletions server/vercel.json

This file was deleted.

38 changes: 38 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": 2,
"projects": [
{
"name": "thefluenspanishh-client",
"root": "client",
"builds": [
{
"src": "client/package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "client/dist"
}
}
],
"routes": [{ "src": "/(.*)", "dest": "client/dist/$1" }],
"rewrites": [
{ "source": "/robots.txt", "destination": "/public/robots.txt" },
{ "source": "/sitemap.xml", "destination": "/public/sitemap.xml" },
{ "source": "/(.*)", "destination": "/client/$1" }
]
},
{
"name": "thefluenspanishhouse-server",
"root": "server",
"builds": [
{
"src": "server/public/src/index.js",
"use": "@vercel/node",
"config": {
"outputDirectory": "server/public"
}
}
],
"routes": [{ "src": "/(.*)", "dest": "server/public/src/index.js" }]
}
]
}

0 comments on commit 089124c

Please sign in to comment.