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" GOOGLE_CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com"
CLIENT_SECRET = "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" GOOGLE_CLIENT_SECRET = "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"
CLIENT_URL = "http://localhost:5173/" GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback"
DB_USER_SERVICE_URL = "http://localhost:3000/" LOGIN_REDIRECT_URL = "https://bytecamp-web.fly.dev/"
SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" #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 RUN npm install
# Install dependencies using npm ci for deterministic builds # 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 the application source code
COPY --link . . 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. # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
# #
app = "auth-service" app = 'byte-camp-auth-service'
primary_region = "sea" primary_region = 'sea'
[build]
[env] [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]] [[services]]
protocol = 'tcp'
internal_port = 8080 internal_port = 8080
protocol = "tcp"
[[services.ports]] [[services.ports]]
handlers = ["http"]
port = 80 port = 80
handlers = ['http']
[[services.ports]] [[services.ports]]
handlers = ["tls", "http"]
port = 443 port = 443
handlers = ['tls', 'http']
[[services.tcp_checks]] [[services.tcp_checks]]
interval = "10s" interval = '10s'
timeout = "2s" timeout = '2s'
grace_period = "5s" grace_period = '5s'
restart_limit = 0
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

View file

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

View file

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

View file

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

View file

@ -5,8 +5,8 @@
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings # 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 #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 # DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable
NODE_PORT=3000 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 # fly.toml file for a Node.js service that connects to an external Postgres DB
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'db-user-service' app = "db-user-service"
primary_region = 'sea' primary_region = "sea"
[env] [build]
PRIMARY_REGION = 'sea' # Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset
[[mounts]] #[env]
source = 'pg_data' #NODE_ENV = "production"
destination = '/data' #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]] [[services]]
protocol = 'tcp' protocol = "tcp"
internal_port = 5432 internal_port = 3000
auto_start_machines = false internal_only = true # Makes this service only accessible internally
[[services.ports]] # Removed public port exposure
port = 5432 # [[services.ports]]
handlers = ['pg_tls'] # port = 80
# handlers = ["http"]
# [[services.ports]]
# port = 443
# handlers = ["tls", "http"]
[services.concurrency] [services.concurrency]
type = 'connections' type = "requests"
hard_limit = 1000 hard_limit = 1000
soft_limit = 1000 soft_limit = 500
[[services]] [[vm]]
protocol = 'tcp' memory = "512mb"
internal_port = 5433 cpu_kind = "shared"
auto_start_machines = false cpus = 1
[[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