diff --git a/.env.example b/.env.example index 0e93cc8..5448f14 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ COMPOSE_PROJECT_NAME='thream-api' HOST='0.0.0.0' PORT='8080' +API_URL='http://localhost:8080' DATABASE_URL='postgresql://user:password@thream-database:5432/thream' JWT_ACCESS_EXPIRES_IN='15 minutes' JWT_ACCESS_SECRET='accessTokenSecret' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1a1e38d..d6b1337 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,11 +32,6 @@ jobs: - name: 'Build' run: 'npm run build' - - name: 'Production migration' - run: 'npm run prisma:migrate:deploy' - env: - DATABASE_URL: ${{ secrets.DATABASE_URL }} - - name: 'Release' run: 'npm run release' env: diff --git a/src/services/users/current/put.ts b/src/services/users/current/put.ts index f8e080c..4ca4a65 100644 --- a/src/services/users/current/put.ts +++ b/src/services/users/current/put.ts @@ -8,7 +8,7 @@ import { fastifyErrors } from '../../../models/utils.js' import authenticateUser from '../../../tools/plugins/authenticateUser.js' import { userCurrentSchema, userSchema } from '../../../models/User.js' import { sendEmail } from '../../../tools/email/sendEmail.js' -import { HOST, PORT } from '../../../tools/configurations/index.js' +import { API_URL } from '../../../tools/configurations/index.js' import { Language, Theme } from '../../../models/UserSettings.js' import { parseStringNullish } from '../../../tools/utils/parseStringNullish.js' @@ -109,7 +109,7 @@ export const putCurrentUser: FastifyPluginAsync = async (fastify) => { await sendEmail({ type: 'confirm-email', email, - url: `${request.protocol}://${HOST}:${PORT}/users/confirm-email?temporaryToken=${temporaryToken}${redirectQuery}`, + url: `${API_URL}/users/confirm-email?temporaryToken=${temporaryToken}${redirectQuery}`, language: settings.language as Language, theme: settings.theme as Theme }) diff --git a/src/services/users/oauth2/discord/callback/get.ts b/src/services/users/oauth2/discord/callback/get.ts index c35869d..2d6cdf9 100644 --- a/src/services/users/oauth2/discord/callback/get.ts +++ b/src/services/users/oauth2/discord/callback/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' @@ -37,7 +37,7 @@ export const getCallbackDiscordOAuth2Service: FastifyPluginAsync = async ( const { redirectURI, code } = request.query const discordUser = await getDiscordUserData( code, - `${request.protocol}://${HOST}:${PORT}/users/oauth2/discord/callback?redirectURI=${redirectURI}` + `${API_URL}/users/oauth2/discord/callback?redirectURI=${redirectURI}` ) const responseJWT = await discordStrategy.callbackSignin({ name: discordUser.username, diff --git a/src/services/users/oauth2/discord/signin/get.ts b/src/services/users/oauth2/discord/signin/get.ts index 8d04a52..6fada51 100644 --- a/src/services/users/oauth2/discord/signin/get.ts +++ b/src/services/users/oauth2/discord/signin/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js' @@ -33,7 +33,7 @@ export const getSigninDiscordOAuth2Service: FastifyPluginAsync = async ( schema: getServiceSchema, handler: async (request, reply) => { const { redirectURI } = request.query - const redirectCallback = `${request.protocol}://${HOST}:${PORT}/users/oauth2/discord/callback?redirectURI=${redirectURI}` + const redirectCallback = `${API_URL}/users/oauth2/discord/callback?redirectURI=${redirectURI}` const url = `${DISCORD_BASE_URL}/oauth2/authorize?client_id=${DISCORD_CLIENT_ID}&scope=identify&response_type=code&redirect_uri=${redirectCallback}` reply.statusCode = 200 return url diff --git a/src/services/users/oauth2/github/callback/get.ts b/src/services/users/oauth2/github/callback/get.ts index 4c08e61..266fcd6 100644 --- a/src/services/users/oauth2/github/callback/get.ts +++ b/src/services/users/oauth2/github/callback/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' @@ -37,7 +37,7 @@ export const getCallbackGitHubOAuth2Service: FastifyPluginAsync = async ( const { redirectURI, code } = request.query const githubUser = await getGitHubUserData( code, - `${request.protocol}://${HOST}:${PORT}/users/oauth2/github/callback?redirectURI=${redirectURI}` + `${API_URL}/users/oauth2/github/callback?redirectURI=${redirectURI}` ) const responseJWT = await githubStrategy.callbackSignin({ name: githubUser.name, diff --git a/src/services/users/oauth2/github/signin/get.ts b/src/services/users/oauth2/github/signin/get.ts index 974501f..b6cfdc2 100644 --- a/src/services/users/oauth2/github/signin/get.ts +++ b/src/services/users/oauth2/github/signin/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js' @@ -33,7 +33,7 @@ export const getSigninGitHubOAuth2Service: FastifyPluginAsync = async ( schema: getServiceSchema, handler: async (request, reply) => { const { redirectURI } = request.query - const redirectCallback = `${request.protocol}://${HOST}:${PORT}/users/oauth2/github/callback?redirectURI=${redirectURI}` + const redirectCallback = `${API_URL}/users/oauth2/github/callback?redirectURI=${redirectURI}` const url = `${GITHUB_BASE_URL}/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&redirect_uri=${redirectCallback}` reply.statusCode = 200 return url diff --git a/src/services/users/oauth2/google/callback/get.ts b/src/services/users/oauth2/google/callback/get.ts index 367d4d3..4fedf7d 100644 --- a/src/services/users/oauth2/google/callback/get.ts +++ b/src/services/users/oauth2/google/callback/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' @@ -37,7 +37,7 @@ export const getCallbackGoogleOAuth2Service: FastifyPluginAsync = async ( const { redirectURI, code } = request.query const googleUser = await getGoogleUserData( code, - `${request.protocol}://${HOST}:${PORT}/users/oauth2/google/callback?redirectURI=${redirectURI}` + `${API_URL}/users/oauth2/google/callback?redirectURI=${redirectURI}` ) const responseJWT = await googleStrategy.callbackSignin({ name: googleUser.name, diff --git a/src/services/users/oauth2/google/signin/get.ts b/src/services/users/oauth2/google/signin/get.ts index bad14eb..3648138 100644 --- a/src/services/users/oauth2/google/signin/get.ts +++ b/src/services/users/oauth2/google/signin/get.ts @@ -1,7 +1,7 @@ import { Static, Type } from '@sinclair/typebox' import { FastifyPluginAsync, FastifySchema } from 'fastify' -import { HOST, PORT } from '../../../../../tools/configurations/index.js' +import { API_URL } from '../../../../../tools/configurations/index.js' import { fastifyErrors } from '../../../../../models/utils.js' import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js' @@ -33,7 +33,7 @@ export const getSigninGoogleOAuth2Service: FastifyPluginAsync = async ( schema: getServiceSchema, handler: async (request, reply) => { const { redirectURI } = request.query - const redirectCallback = `${request.protocol}://${HOST}:${PORT}/users/oauth2/google/callback?redirectURI=${redirectURI}` + const redirectCallback = `${API_URL}/users/oauth2/google/callback?redirectURI=${redirectURI}` const url = `${GOOGLE_BASE_URL}?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=${redirectCallback}&response_type=code&scope=profile&access_type=online` reply.statusCode = 200 return url diff --git a/src/services/users/signup/post.ts b/src/services/users/signup/post.ts index 9b8c9e7..69ec4cd 100644 --- a/src/services/users/signup/post.ts +++ b/src/services/users/signup/post.ts @@ -12,7 +12,7 @@ import { userPublicSchema } from '../../../models/User.js' import { sendEmail } from '../../../tools/email/sendEmail.js' -import { HOST, PORT } from '../../../tools/configurations/index.js' +import { API_URL } from '../../../tools/configurations/index.js' const queryPostSignupSchema = Type.Object({ redirectURI: Type.Optional(Type.String({ format: 'uri-reference' })) @@ -76,7 +76,7 @@ export const postSignupUser: FastifyPluginAsync = async (fastify) => { await sendEmail({ type: 'confirm-email', email, - url: `${request.protocol}://${HOST}:${PORT}/users/confirm-email?temporaryToken=${temporaryToken}${redirectQuery}`, + url: `${API_URL}/users/confirm-email?temporaryToken=${temporaryToken}${redirectQuery}`, language, theme }) diff --git a/src/tools/configurations/index.ts b/src/tools/configurations/index.ts index 743a316..fdfea8a 100644 --- a/src/tools/configurations/index.ts +++ b/src/tools/configurations/index.ts @@ -6,6 +6,7 @@ dotenv.config() export const PORT = parseInt(process.env.PORT ?? '8080', 10) export const HOST = process.env.HOST ?? '0.0.0.0' +export const API_URL = process.env.API_URL ?? `http://${HOST}:${PORT}` export const JWT_ACCESS_SECRET = process.env.JWT_ACCESS_SECRET ?? 'accessTokenSecret' export const JWT_REFRESH_SECRET =