Sept18_2025
This commit is contained in:
parent
50e4802448
commit
229cc21dac
File diff suppressed because one or more lines are too long
@ -71,5 +71,11 @@ config.apiUrl = `${config.host}${config.port ? `:${config.port}` : ``}/api`;
|
||||
config.swaggerUrl = `${config.swaggerUI}${config.swaggerPort}`;
|
||||
config.uiUrl = `${config.hostUI}${config.portUI ? `:${config.portUI}` : ``}/#`;
|
||||
config.backUrl = `${config.hostUI}${config.portUI ? `:${config.portUI}` : ``}`;
|
||||
// Payment gateway configurations
|
||||
config.stripeSecretKey = process.env.STRIPE_SECRET_KEY || 'sk_test_dummy';
|
||||
config.stripeWebhookSecret = process.env.STRIPE_WEBHOOK_SECRET || 'whsec_dummy';
|
||||
config.paypalClientId = process.env.PAYPAL_CLIENT_ID || 'paypal_client_dummy';
|
||||
config.paypalClientSecret = process.env.PAYPAL_CLIENT_SECRET || 'paypal_secret_dummy';
|
||||
|
||||
|
||||
module.exports = config;
|
||||
|
||||
@ -25,6 +25,11 @@ module.exports = function (sequelize, DataTypes) {
|
||||
allowNull: true,
|
||||
unique: true,
|
||||
},
|
||||
certificate_url: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
|
||||
@ -95,6 +95,39 @@ app.use(
|
||||
);
|
||||
|
||||
app.use(cors({ origin: true }));
|
||||
|
||||
// Stripe webhook endpoint
|
||||
const stripe = require('stripe')(config.stripeSecretKey);
|
||||
app.post(
|
||||
'/api/webhooks/stripe',
|
||||
express.raw({ type: 'application/json' }),
|
||||
async (req, res) => {
|
||||
const sig = req.headers['stripe-signature'];
|
||||
let event;
|
||||
try {
|
||||
event = stripe.webhooks.constructEvent(
|
||||
req.body,
|
||||
sig,
|
||||
config.stripeWebhookSecret,
|
||||
);
|
||||
} catch (err) {
|
||||
return res.status(400).send(`Webhook Error: ${err.message}`);
|
||||
}
|
||||
if (event.type === 'checkout.session.completed') {
|
||||
const session = event.data.object;
|
||||
const enrollmentId = session.metadata.enrollmentId;
|
||||
await db.enrollments.update(
|
||||
{
|
||||
payment_status: 'completed',
|
||||
certificate_url: `${config.uiUrl}/certificate?enrollmentId=${enrollmentId}`,
|
||||
},
|
||||
{ where: { id: enrollmentId } },
|
||||
);
|
||||
}
|
||||
res.json({ received: true });
|
||||
},
|
||||
);
|
||||
|
||||
require('./auth/auth');
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
@ -26,6 +26,12 @@ const nextConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
rewrites: async () => [
|
||||
{
|
||||
source: '/api/:path*',
|
||||
destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
export const hostApi =
|
||||
process.env.NODE_ENV === 'development' && !process.env.NEXT_PUBLIC_BACK_API
|
||||
? 'http://localhost'
|
||||
: '';
|
||||
export const portApi =
|
||||
process.env.NODE_ENV === 'development' && !process.env.NEXT_PUBLIC_BACK_API
|
||||
? 8080
|
||||
: '';
|
||||
export const baseURLApi = `${hostApi}${portApi ? `:${portApi}` : ``}/api`;
|
||||
const trimSlash = (url: string) => url.replace(/\/$/, '');
|
||||
const apiUrlEnv = process.env.NEXT_PUBLIC_API_URL;
|
||||
const defaultDevApi = 'http://localhost:8080';
|
||||
const host = apiUrlEnv
|
||||
? trimSlash(apiUrlEnv)
|
||||
: process.env.NODE_ENV === 'development'
|
||||
? defaultDevApi
|
||||
: '';
|
||||
export const baseURLApi = host ? `${host}/api` : '/api';
|
||||
|
||||
export const localStorageDarkModeKey = 'darkMode';
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import axios from 'axios';
|
||||
import { baseURLApi } from '../config';
|
||||
|
||||
|
||||
export async function getPexelsImage() {
|
||||
try {
|
||||
const response = await axios.get(`/pexels/image`);
|
||||
const response = await axios.get(`${baseURLApi}/pexels/image`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching image:', error);
|
||||
@ -12,7 +14,7 @@ export async function getPexelsImage() {
|
||||
|
||||
export async function getPexelsVideo() {
|
||||
try {
|
||||
const response = await axios.get(`/pexels/video`);
|
||||
const response = await axios.get(`${baseURLApi}/pexels/video`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching video:', error);
|
||||
@ -50,7 +52,7 @@ export async function getMultiplePexelsImages(
|
||||
const queryString = missingQueries.join(',');
|
||||
|
||||
try {
|
||||
const response = await axios.get(`/pexels/multiple-images`, {
|
||||
const response = await axios.get(`${baseURLApi}/pexels/multiple-images`, {
|
||||
params: { queries: queryString },
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user