Code changes to make it work with Fly.io

This commit is contained in:
JBB0807 2025-04-21 17:14:11 -07:00
parent 5b93901976
commit 0695a01f17
9 changed files with 100 additions and 85 deletions

View file

@ -1,5 +1,10 @@
CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com"
CLIENT_SECRET = "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"
CLIENT_URL = "http://localhost:5173/"
DB_USER_SERVICE_URL = "http://localhost:3000/"
SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"
GOOGLE_CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET = "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"
GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback"
LOGIN_REDIRECT_URL = "https://bytecamp-web.fly.dev/"
#DB_USER_SERVICE_URL = "http://localhost:3000/"
DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/"
AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"
fly secrets set GOOGLE_CALLBACK_URL=https://byte-camp-auth-service.fly.dev/auth/google/callback
#fly secrets set GOOGLE_CLIENT_ID=485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=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 LOGIN_REDIRECT_URL=https://bytecamp-web.fly.dev/ DB_USER_SERVICE_URL=https://db-user-service.fly.dev:3000/ AUTH_SESSION_KEY=f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42

View file

@ -11,7 +11,7 @@ COPY . .
RUN npm install
# Install dependencies using npm ci for deterministic builds
RUN --mount=type=cache,target=/root/.npm npm ci --production
# RUN --mount=type=cache,target=/root/.npm npm ci --production
# Copy the application source code
COPY --link . .

View file

@ -1,28 +1,42 @@
# fly.toml app configuration file generated for snakebyte on 2025-01-04T01:06:05-08:00
# fly.toml app configuration file generated for byte-camp-auth-service on 2025-04-21T14:38:25-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "auth-service"
primary_region = "sea"
app = 'byte-camp-auth-service'
primary_region = 'sea'
[build]
[env]
PORT = "8080"
PORT = '8080'
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[services]]
protocol = 'tcp'
internal_port = 8080
protocol = "tcp"
[[services.ports]]
handlers = ["http"]
port = 80
handlers = ['http']
[[services.ports]]
handlers = ["tls", "http"]
port = 443
handlers = ['tls', 'http']
[[services.tcp_checks]]
interval = "10s"
timeout = "2s"
grace_period = "5s"
restart_limit = 0
interval = '10s'
timeout = '2s'
grace_period = '5s'
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

View file

@ -6,9 +6,9 @@ const passport = require("passport");
passport.use(
new GoogleStrategy(
{
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "/auth/google/callback",
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
scope: ["profile", "email"],
},
function (accessToken, refreshToken, profile, callback) {

View file

@ -19,7 +19,7 @@ router.get("/login", (req, res) => {
})
.then(response => {
console.log("User registration response:", response.data);
res.redirect(process.env.CLIENT_URL);
res.redirect(process.env.LOGIN_REDIRECT_URL);
})
.catch(error => {
console.error("Error registering user:", error.message);
@ -42,7 +42,7 @@ router.get("/google", passport.authenticate("google", ["profile", "email"]));
router.get("/logout", (req, res) => {
req.logOut();
res.redirect(process.env.CLIENT_URL);
res.redirect(process.env.LOGIN_REDIRECT_URL);
});
module.exports = router;

View file

@ -11,7 +11,7 @@ const app = express();
app.use(
session({
secret: process.env.SESSION_KEY,
secret: process.env.AUTH_SESSION_KEY,
resave: false,
saveUninitialized: false,
cookie: {
@ -25,7 +25,7 @@ app.use(passport.session());
app.use(
cors({
origin: "http://localhost:5173",
origin: "https://bytecamp-web.fly.dev",
methods: "GET",
credentials: true,
})

View file

@ -5,8 +5,8 @@
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
#use this when testing local, remmber to run the proxy command
DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public"
# DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public"
# DATABASE_URL="postgres://postgres:w2eSd47GJEdqvMf@snakebyte.internal:5432"
DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable"
# DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable
NODE_PORT=3000

View file

@ -0,0 +1,20 @@
# syntax=docker/dockerfile:1
# Use the official Node.js image as the base image
ARG NODE_VERSION=22.13.1
FROM node:${NODE_VERSION}-slim AS base
# Set the working directory
WORKDIR /app
COPY . .
RUN apt-get update -y && apt-get install -y openssl && npm install && npx prisma generate
# Copy the application source code
COPY --link . .
# Expose the application port
EXPOSE 3000
# Define the command to run the application
CMD ["node", "app.js"]

View file

@ -1,69 +1,45 @@
# fly.toml app configuration file generated for snakebyte on 2025-01-04T01:06:05-08:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
# fly.toml file for a Node.js service that connects to an external Postgres DB
app = 'db-user-service'
primary_region = 'sea'
app = "db-user-service"
primary_region = "sea"
[env]
PRIMARY_REGION = 'sea'
[build]
# Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset
[[mounts]]
source = 'pg_data'
destination = '/data'
#[env]
#NODE_ENV = "production"
#DATABASE_URL = "postgresql://user:password@hostname:port/dbname"
# you can also leave DATABASE_URL unset here and use secrets instead
# Removed the [http_service] section to disable public HTTP/HTTPS access
# [http_service]
# internal_port = 3000
# force_https = true
# auto_stop_machines = true
# auto_start_machines = true
# min_machines_running = 0
# processes = ["app"]
[[services]]
protocol = 'tcp'
internal_port = 5432
auto_start_machines = false
protocol = "tcp"
internal_port = 3000
internal_only = true # Makes this service only accessible internally
[[services.ports]]
port = 5432
handlers = ['pg_tls']
# Removed public port exposure
# [[services.ports]]
# port = 80
# handlers = ["http"]
# [[services.ports]]
# port = 443
# handlers = ["tls", "http"]
[services.concurrency]
type = 'connections'
type = "requests"
hard_limit = 1000
soft_limit = 1000
soft_limit = 500
[[services]]
protocol = 'tcp'
internal_port = 5433
auto_start_machines = false
[[services.ports]]
port = 5433
handlers = ['pg_tls']
[services.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000
[checks]
[checks.pg]
port = 5500
type = 'http'
interval = '15s'
timeout = '10s'
path = '/flycheck/pg'
[checks.role]
port = 5500
type = 'http'
interval = '15s'
timeout = '10s'
path = '/flycheck/role'
[checks.vm]
port = 5500
type = 'http'
interval = '15s'
timeout = '10s'
path = '/flycheck/vm'
[[metrics]]
port = 9187
path = '/metrics'
https = false
[[vm]]
memory = "512mb"
cpu_kind = "shared"
cpus = 1