2
1
mirror of https://github.com/Thream/api.git synced 2024-07-06 12:50:12 +02:00

fix: usage of API_URL

This commit is contained in:
Divlo 2022-03-21 20:44:15 +01:00
parent ad903da6a4
commit 694ac58aad
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
11 changed files with 18 additions and 21 deletions

View File

@ -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'

View File

@ -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:

View File

@ -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
})

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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
})

View File

@ -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 =