Compare commits

..

No commits in common. "master" and "littleFixes" have entirely different histories.

103 changed files with 8606 additions and 5148 deletions

View File

@ -1,28 +0,0 @@
# ===========================================
# COOLIFY ENVIRONMENT VARIABLES
# Copy these to Coolify UI: Environment Variables section
# ===========================================
# Database Password (you should already have this set)
DATABASE_PASSWORD=abreubre776677112233
# Backend JWT Secret (REQUIRED - MISSING!)
JWT_SECRET=Xt4mwkbFEw83dSMXCv6W0Ut6YoTgIkYO62eticw0CfxkZhYSplDbjeUOyrnwyWK34Pt3nrnmtE5+khKxeoHiSA==
# Strapi API Token (leave empty for now - will set after making API public)
STRAPI_API_TOKEN=
# Strapi Security Keys (REQUIRED)
STRAPI_APP_KEYS=Jlt1Pu+ZBzcTSYazU8ZlEMOZyj4F9MO9YVAJmkaKrnk=,V2VSvJQrZ61jk8MtVkhC2RrKcm3XvJzmYTi73NItPYQ=,dhvlKrjeYGbCGaZznVTEJZLcAjIIwAtNmT6/i5Zq09I=,qDCKh9Pdep3P4ZlX+OCsKUwj/VZKul959RGbxXdiyf8=
STRAPI_API_TOKEN_SALT=MkkvTfDJkwEPznUVfbiKj3SSWPw/MKqrOIRxN9cyWLk=
STRAPI_ADMIN_JWT_SECRET=RpqNlR20k4VF2x1rzRvjUsg46zN2X4YcfBowbjdvqJo=
STRAPI_TRANSFER_TOKEN_SALT=96PznECGwwinWXB8fhlHwE11+0XU5TaJwTaztQPaQw4=
STRAPI_JWT_SECRET=3CGgFzvM8ykfndK2pqcCb7U5W3FcBF0SXwalj1kby6s=
STRAPI_ENCRYPTION_KEY=8V99V0CfSxJZLvgXGRBv/zndKH2FnPQ/JVmXa1OEfZ8=
# Push Notification VAPID Keys (for PWA notifications)
VAPID_PUBLIC_KEY=BEUVi1YA6wyD1Mt31M8nbsz7ctVC1wxURkz4bHdrexbtUzDETS90MOpS-QFebnXt_Dx_zvntPHCno6bwsK3pOxU
VAPID_PRIVATE_KEY=XJIYJyV1KkfEwnHa1vy4Jb3FPRg27eFton1Tdsep8fI
# VAPID Subject (optional - defaults to mailto:contact@placebo.mk)
VAPID_SUBJECT=mailto:contact@placebo.mk

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,11 @@ FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Copy package files # Copy package files
COPY package.json package-lock.json* ./ COPY package*.json ./
COPY package-lock.json* ./
# Install ALL dependencies (including devDependencies for build) # Install dependencies
RUN npm install --legacy-peer-deps RUN npm ci --only=production
# Copy source code # Copy source code
COPY . . COPY . .
@ -17,9 +18,6 @@ COPY . .
# Build TypeScript # Build TypeScript
RUN npm run build RUN npm run build
# Prune devDependencies after build (suppress warning)
RUN npm prune --omit=dev
# Production stage # Production stage
FROM node:20-alpine FROM node:20-alpine
@ -34,6 +32,9 @@ COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./ COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./
# Copy environment configuration
COPY --chown=nodejs:nodejs .env.example .env
# Switch to non-root user # Switch to non-root user
USER nodejs USER nodejs
@ -45,4 +46,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
EXPOSE 3000 EXPOSE 3000
# Start application # Start application
CMD ["node", "dist/src/main.js"] CMD ["node", "dist/main.js"]

View File

@ -1,13 +0,0 @@
#!/bin/sh
# Backend entrypoint script - seeds admin on first run
echo "Starting Placebo.mk Backend..."
# Run admin seed script (idempotent - won't recreate if exists)
# Temporarily disabled to fix startup issues
# echo "Checking for admin user..."
# node dist/scripts/seed-admin.js || echo "Warning: Admin seed failed, continuing..."
# Start the application
echo "Starting NestJS application..."
exec node dist/src/main.js

View File

@ -40,7 +40,6 @@
"@types/bcrypt": "^6.0.0", "@types/bcrypt": "^6.0.0",
"@types/passport-jwt": "^4.0.1", "@types/passport-jwt": "^4.0.1",
"@types/passport-local": "^1.0.38", "@types/passport-local": "^1.0.38",
"axios": "^1.13.6",
"bcrypt": "^6.0.0", "bcrypt": "^6.0.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.3", "class-validator": "^0.14.3",

View File

@ -1,6 +1,5 @@
import { Controller, Get } from '@nestjs/common'; import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { Public } from './modules/auth/public.decorator';
@Controller() @Controller()
export class AppController { export class AppController {
@ -10,13 +9,4 @@ export class AppController {
getHello(): string { getHello(): string {
return this.appService.getHello(); return this.appService.getHello();
} }
@Public()
@Get('health')
healthCheck(): { status: string; timestamp: string } {
return {
status: 'ok',
timestamp: new Date().toISOString(),
};
}
} }

View File

@ -1,7 +1,6 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_GUARD } from '@nestjs/core';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { ArticlesModule } from './modules/articles.module'; import { ArticlesModule } from './modules/articles.module';
@ -24,7 +23,6 @@ import {
} from './modules/entities'; } from './modules/entities';
import { ShareEvent } from './modules/analytics/analytics.entity'; import { ShareEvent } from './modules/analytics/analytics.entity';
import { PushSubscriptionEntity } from './modules/push/push-subscription.entity'; import { PushSubscriptionEntity } from './modules/push/push-subscription.entity';
import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
@Module({ @Module({
imports: [ imports: [
@ -63,12 +61,6 @@ import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
PushModule, PushModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [ providers: [AppService],
AppService,
{
provide: APP_GUARD,
useClass: JwtAuthPublicGuard,
},
],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,28 +1,20 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory, Reflector } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common'; import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
// Build allowed origins list from environment variables
const allowedOrigins = [ const allowedOrigins = [
process.env.FRONTEND_URL ?? 'http://localhost:5173', process.env.FRONTEND_URL ?? 'http://localhost:5173',
'https://placebo.mk', // Production domain
'https://www.placebo.mk', // Also allow www subdomain
process.env.PWA_URL ?? 'http://localhost:5174', process.env.PWA_URL ?? 'http://localhost:5174',
process.env.STRAPI_URL ?? 'http://localhost:1337', process.env.STRAPI_URL ?? 'http://localhost:1337',
].filter(Boolean); // Remove any undefined/null values ];
console.log('CORS enabled for origins:', allowedOrigins);
app.enableCors({ app.enableCors({
origin: allowedOrigins, origin: allowedOrigins,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'Accept', 'Origin'],
exposedHeaders: ['Content-Range', 'X-Content-Range'],
credentials: true, credentials: true,
maxAge: 3600,
}); });
app.setGlobalPrefix('api/v1'); app.setGlobalPrefix('api/v1');
@ -36,6 +28,10 @@ async function bootstrap() {
}), }),
); );
// Apply global authentication guard
const reflector = app.get(Reflector);
app.useGlobalGuards(new JwtAuthPublicGuard(reflector));
const port = process.env.PORT ?? 3000; const port = process.env.PORT ?? 3000;
const host = '0.0.0.0'; // Bind to all interfaces for Docker const host = '0.0.0.0'; // Bind to all interfaces for Docker
await app.listen(port, host); await app.listen(port, host);

View File

@ -5,7 +5,7 @@ export class TrackShareDto {
@IsUUID() @IsUUID()
articleId: string; articleId: string;
@IsEnum(['facebook', 'twitter', 'instagram', 'tiktok', 'telegram', 'link']) @IsEnum(['facebook', 'twitter', 'whatsapp', 'telegram', 'link'])
platform: SharePlatform; platform: SharePlatform;
@IsOptional() @IsOptional()
@ -36,8 +36,7 @@ export class ShareStatsResponse {
articleTitle: string; articleTitle: string;
facebookShares: number; facebookShares: number;
twitterShares: number; twitterShares: number;
instagramShares: number; whatsappShares: number;
tiktokShares: number;
telegramShares: number; telegramShares: number;
linkShares: number; linkShares: number;
totalShares: number; totalShares: number;

View File

@ -11,8 +11,7 @@ import { Article } from '../entities';
export type SharePlatform = export type SharePlatform =
| 'facebook' | 'facebook'
| 'twitter' | 'twitter'
| 'instagram' | 'whatsapp'
| 'tiktok'
| 'telegram' | 'telegram'
| 'link'; | 'link';
@ -49,8 +48,7 @@ export interface ShareStats {
articleTitle: string; articleTitle: string;
facebookShares: number; facebookShares: number;
twitterShares: number; twitterShares: number;
instagramShares: number; whatsappShares: number;
tiktokShares: number;
telegramShares: number; telegramShares: number;
linkShares: number; linkShares: number;
totalShares: number; totalShares: number;

View File

@ -53,10 +53,8 @@ export class AnalyticsService {
return 'facebookShares'; return 'facebookShares';
case 'twitter': case 'twitter':
return 'twitterShares'; return 'twitterShares';
case 'instagram': case 'whatsapp':
return 'instagramShares'; return 'whatsappShares';
case 'tiktok':
return 'tiktokShares';
case 'telegram': case 'telegram':
return 'telegramShares'; return 'telegramShares';
default: default:
@ -74,21 +72,20 @@ export class AnalyticsService {
'article.title as "articleTitle"', 'article.title as "articleTitle"',
'article.facebookShares as "facebookShares"', 'article.facebookShares as "facebookShares"',
'article.twitterShares as "twitterShares"', 'article.twitterShares as "twitterShares"',
'article.instagramShares as "instagramShares"', 'article.whatsappShares as "whatsappShares"',
'article.tiktokShares as "tiktokShares"',
'article.telegramShares as "telegramShares"', 'article.telegramShares as "telegramShares"',
'article.views as "views"', 'article.views as "views"',
'article.createdAt as "createdAt"', 'article.createdAt as "createdAt"',
'article.updatedAt as "updatedAt"', 'article.updatedAt as "updatedAt"',
]) ])
.addSelect( .addSelect(
`(article.facebookShares + article.twitterShares + article.instagramShares + article.tiktokShares + article.telegramShares) as "totalShares"`, `(article.facebookShares + article.twitterShares + article.whatsappShares + article.telegramShares) as "totalShares"`,
) )
.addSelect( .addSelect(
`CASE `CASE
WHEN article.views > 0 WHEN article.views > 0
THEN ROUND( THEN ROUND(
(article.facebookShares + article.twitterShares + article.instagramShares + article.tiktokShares + article.telegramShares)::decimal / article.views * 100, (article.facebookShares + article.twitterShares + article.whatsappShares + article.telegramShares)::decimal / article.views * 100,
2 2
) )
ELSE 0 ELSE 0
@ -120,8 +117,7 @@ export class AnalyticsService {
articleTitle: string; articleTitle: string;
facebookShares: string; facebookShares: string;
twitterShares: string; twitterShares: string;
instagramShares: string; whatsappShares: string;
tiktokShares: string;
telegramShares: string; telegramShares: string;
views: string; views: string;
createdAt: string; createdAt: string;
@ -142,16 +138,11 @@ export class AnalyticsService {
const facebookShares = parseInt(rawResult.facebookShares) || 0; const facebookShares = parseInt(rawResult.facebookShares) || 0;
const twitterShares = parseInt(rawResult.twitterShares) || 0; const twitterShares = parseInt(rawResult.twitterShares) || 0;
const instagramShares = parseInt(rawResult.instagramShares) || 0; const whatsappShares = parseInt(rawResult.whatsappShares) || 0;
const tiktokShares = parseInt(rawResult.tiktokShares) || 0;
const telegramShares = parseInt(rawResult.telegramShares) || 0; const telegramShares = parseInt(rawResult.telegramShares) || 0;
const views = parseInt(rawResult.views) || 0; const views = parseInt(rawResult.views) || 0;
const baseTotalShares = const baseTotalShares =
facebookShares + facebookShares + twitterShares + whatsappShares + telegramShares;
twitterShares +
instagramShares +
tiktokShares +
telegramShares;
const totalShares = baseTotalShares + linkShares; const totalShares = baseTotalShares + linkShares;
const shareRate = const shareRate =
views > 0 ? parseFloat(((totalShares / views) * 100).toFixed(2)) : 0; views > 0 ? parseFloat(((totalShares / views) * 100).toFixed(2)) : 0;
@ -161,8 +152,7 @@ export class AnalyticsService {
articleTitle: rawResult.articleTitle, articleTitle: rawResult.articleTitle,
facebookShares, facebookShares,
twitterShares, twitterShares,
instagramShares, whatsappShares,
tiktokShares,
telegramShares, telegramShares,
linkShares, linkShares,
totalShares, totalShares,
@ -227,16 +217,14 @@ export class AnalyticsService {
totalShares: number; totalShares: number;
facebookShares: number; facebookShares: number;
twitterShares: number; twitterShares: number;
instagramShares: number; whatsappShares: number;
tiktokShares: number;
telegramShares: number; telegramShares: number;
linkShares: number; linkShares: number;
}> { }> {
interface ArticleStatsRaw { interface ArticleStatsRaw {
facebookShares: string; facebookShares: string;
twitterShares: string; twitterShares: string;
instagramShares: string; whatsappShares: string;
tiktokShares: string;
telegramShares: string; telegramShares: string;
} }
@ -245,8 +233,7 @@ export class AnalyticsService {
.select([ .select([
'SUM(article.facebookShares) as facebookShares', 'SUM(article.facebookShares) as facebookShares',
'SUM(article.twitterShares) as twitterShares', 'SUM(article.twitterShares) as twitterShares',
'SUM(article.instagramShares) as instagramShares', 'SUM(article.whatsappShares) as whatsappShares',
'SUM(article.tiktokShares) as tiktokShares',
'SUM(article.telegramShares) as telegramShares', 'SUM(article.telegramShares) as telegramShares',
]) ])
.getRawOne()) as ArticleStatsRaw; .getRawOne()) as ArticleStatsRaw;
@ -257,15 +244,13 @@ export class AnalyticsService {
const facebookShares = parseInt(articleStats?.facebookShares || '0') || 0; const facebookShares = parseInt(articleStats?.facebookShares || '0') || 0;
const twitterShares = parseInt(articleStats?.twitterShares || '0') || 0; const twitterShares = parseInt(articleStats?.twitterShares || '0') || 0;
const instagramShares = parseInt(articleStats?.instagramShares || '0') || 0; const whatsappShares = parseInt(articleStats?.whatsappShares || '0') || 0;
const tiktokShares = parseInt(articleStats?.tiktokShares || '0') || 0;
const telegramShares = parseInt(articleStats?.telegramShares || '0') || 0; const telegramShares = parseInt(articleStats?.telegramShares || '0') || 0;
const totalShares = const totalShares =
facebookShares + facebookShares +
twitterShares + twitterShares +
instagramShares + whatsappShares +
tiktokShares +
telegramShares + telegramShares +
linkShares; linkShares;
@ -273,8 +258,7 @@ export class AnalyticsService {
totalShares, totalShares,
facebookShares, facebookShares,
twitterShares, twitterShares,
instagramShares, whatsappShares,
tiktokShares,
telegramShares, telegramShares,
linkShares, linkShares,
}; };

View File

@ -98,9 +98,6 @@ export class ArticlesService {
throw new NotFoundException(`Article with ID ${id} not found`); throw new NotFoundException(`Article with ID ${id} not found`);
} }
// Increment view count
await this.articleRepository.increment({ id }, 'views', 1);
return article; return article;
} }
@ -114,27 +111,11 @@ export class ArticlesService {
throw new NotFoundException(`Article with slug ${slug} not found`); throw new NotFoundException(`Article with slug ${slug} not found`);
} }
// Increment view count
await this.articleRepository.increment({ slug }, 'views', 1);
return article;
}
async findOneWithoutIncrement(id: string): Promise<Article> {
const article = await this.articleRepository.findOne({
where: { id },
relations: ['author', 'category'],
});
if (!article) {
throw new NotFoundException(`Article with ID ${id} not found`);
}
return article; return article;
} }
async update(id: string, dto: UpdateArticleDto): Promise<Article> { async update(id: string, dto: UpdateArticleDto): Promise<Article> {
const article = await this.findOneWithoutIncrement(id); const article = await this.findOne(id);
const oldStatus = article.status; const oldStatus = article.status;
Object.assign(article, dto); Object.assign(article, dto);
const savedArticle = await this.articleRepository.save(article); const savedArticle = await this.articleRepository.save(article);
@ -163,7 +144,7 @@ export class ArticlesService {
} }
async remove(id: string): Promise<void> { async remove(id: string): Promise<void> {
const article = await this.findOneWithoutIncrement(id); const article = await this.findOne(id);
// Delete from Strapi if article has strapiId // Delete from Strapi if article has strapiId
if (article.strapiId) { if (article.strapiId) {
@ -179,7 +160,7 @@ export class ArticlesService {
} }
async archive(id: string): Promise<Article> { async archive(id: string): Promise<Article> {
const article = await this.findOneWithoutIncrement(id); const article = await this.findOne(id);
article.status = ArticleStatus.ARCHIVED; article.status = ArticleStatus.ARCHIVED;
const savedArticle = await this.articleRepository.save(article); const savedArticle = await this.articleRepository.save(article);
@ -206,7 +187,7 @@ export class ArticlesService {
id: string, id: string,
status: ArticleStatus = ArticleStatus.PUBLISHED, status: ArticleStatus = ArticleStatus.PUBLISHED,
): Promise<Article> { ): Promise<Article> {
const article = await this.findOneWithoutIncrement(id); const article = await this.findOne(id);
const wasDraft = article.status === ArticleStatus.DRAFT; const wasDraft = article.status === ArticleStatus.DRAFT;
article.status = status; article.status = status;
const savedArticle = await this.articleRepository.save(article); const savedArticle = await this.articleRepository.save(article);

View File

@ -249,10 +249,7 @@ export class Article {
twitterShares: number; twitterShares: number;
@Column({ default: 0 }) @Column({ default: 0 })
instagramShares: number; whatsappShares: number;
@Column({ default: 0 })
tiktokShares: number;
@Column({ default: 0 }) @Column({ default: 0 })
telegramShares: number; telegramShares: number;

View File

@ -30,6 +30,12 @@ export class PushController {
@Post('subscribe') @Post('subscribe')
@HttpCode(HttpStatus.CREATED) @HttpCode(HttpStatus.CREATED)
async subscribe(@Body() dto: SubscribeDto): Promise<{ success: boolean }> { async subscribe(@Body() dto: SubscribeDto): Promise<{ success: boolean }> {
console.log('Received push subscription:', {
endpoint: dto.endpoint?.substring(0, 50) + '...',
hasP256dh: !!dto.p256dh,
hasAuth: !!dto.auth,
userId: dto.userId,
});
await this.pushService.subscribe(dto); await this.pushService.subscribe(dto);
return { success: true }; return { success: true };
} }

View File

@ -49,11 +49,15 @@ export class PushService implements OnModuleInit {
} }
async subscribe(dto: SubscribeDto): Promise<PushSubscriptionEntity> { async subscribe(dto: SubscribeDto): Promise<PushSubscriptionEntity> {
this.logger.log('Subscribing push notification...');
this.logger.debug(`Endpoint: ${dto.endpoint?.substring(0, 50)}...`);
const existing = await this.subscriptionRepo.findOne({ const existing = await this.subscriptionRepo.findOne({
where: { endpoint: dto.endpoint }, where: { endpoint: dto.endpoint },
}); });
if (existing) { if (existing) {
this.logger.log('Subscription already exists, updating...');
if (dto.userId && existing.userId !== dto.userId) { if (dto.userId && existing.userId !== dto.userId) {
existing.userId = dto.userId; existing.userId = dto.userId;
return this.subscriptionRepo.save(existing); return this.subscriptionRepo.save(existing);
@ -61,6 +65,7 @@ export class PushService implements OnModuleInit {
return existing; return existing;
} }
this.logger.log('Creating new subscription...');
const subscription = this.subscriptionRepo.create({ const subscription = this.subscriptionRepo.create({
endpoint: dto.endpoint, endpoint: dto.endpoint,
p256dh: dto.p256dh, p256dh: dto.p256dh,
@ -68,7 +73,9 @@ export class PushService implements OnModuleInit {
userId: dto.userId ?? null, userId: dto.userId ?? null,
}); });
return this.subscriptionRepo.save(subscription); const saved = await this.subscriptionRepo.save(subscription);
this.logger.log(`Subscription saved with ID: ${saved.id}`);
return saved;
} }
async unsubscribe(dto: UnsubscribeDto): Promise<void> { async unsubscribe(dto: UnsubscribeDto): Promise<void> {

View File

@ -1,4 +1,4 @@
import { Controller, Post, Get, Body, Logger } from '@nestjs/common'; import { Controller, Post, Body, Logger } from '@nestjs/common';
import { StrapiService } from './strapi.service'; import { StrapiService } from './strapi.service';
import { Public } from './auth/public.decorator'; import { Public } from './auth/public.decorator';
@ -120,28 +120,18 @@ export class StrapiController {
} }
@Post('sync/all') @Post('sync/all')
@Public()
async syncAllArticles() { async syncAllArticles() {
await this.strapiService.syncArticles(); await this.strapiService.syncArticles();
return { message: 'Articles sync completed' }; return { message: 'Articles sync completed' };
} }
@Get('sync/all')
@Public()
async syncAllArticlesGet() {
await this.strapiService.syncArticles();
return { message: 'Articles sync completed' };
}
@Post('sync/live-blogs') @Post('sync/live-blogs')
@Public()
async syncAllLiveBlogs() { async syncAllLiveBlogs() {
await this.strapiService.syncLiveBlogs(); await this.strapiService.syncLiveBlogs();
return { message: 'Live blogs sync completed' }; return { message: 'Live blogs sync completed' };
} }
@Post('sync/everything') @Post('sync/everything')
@Public()
async syncEverything() { async syncEverything() {
await Promise.all([ await Promise.all([
this.strapiService.syncArticles(), this.strapiService.syncArticles(),

View File

@ -87,7 +87,6 @@ interface StrapiResponse<T> {
export class StrapiService { export class StrapiService {
private readonly logger = new Logger(StrapiService.name); private readonly logger = new Logger(StrapiService.name);
private readonly strapiUrl: string; private readonly strapiUrl: string;
private readonly strapiPublicUrl: string;
private readonly strapiApiToken: string; private readonly strapiApiToken: string;
constructor( constructor(
@ -102,28 +101,14 @@ export class StrapiService {
) { ) {
this.strapiUrl = this.strapiUrl =
this.configService.get<string>('STRAPI_URL') || 'http://localhost:1337'; this.configService.get<string>('STRAPI_URL') || 'http://localhost:1337';
this.strapiPublicUrl =
this.configService.get<string>('STRAPI_PUBLIC_URL') ||
this.strapiUrl.replace('cms:', 'localhost:');
this.strapiApiToken = this.strapiApiToken =
this.configService.get<string>('STRAPI_API_TOKEN') || ''; this.configService.get<string>('STRAPI_API_TOKEN') || '';
} }
private getHeaders() { private getHeaders() {
// Use public API access - no authentication needed return {
// Strapi Public role has been configured to allow article access Authorization: `Bearer ${this.strapiApiToken}`,
return {}; };
}
private generateSlug(title: string): string {
// Generate slug from title if missing
return title
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, '') // Remove special characters
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/-+/g, '-') // Replace multiple hyphens with single hyphen
.substring(0, 100); // Limit length
} }
private async findOrCreateCategory( private async findOrCreateCategory(
@ -135,7 +120,6 @@ export class StrapiService {
// Map CMS category slugs to Macedonian display names // Map CMS category slugs to Macedonian display names
const categoryMap: Record<string, { name: string; description: string }> = { const categoryMap: Record<string, { name: string; description: string }> = {
general: { name: 'Општо', description: 'Општи вести и теми' },
sport: { name: 'Спорт', description: 'Спортски вести и анализи' }, sport: { name: 'Спорт', description: 'Спортски вести и анализи' },
art: { name: 'Уметност', description: 'Уметност, култура и забава' }, art: { name: 'Уметност', description: 'Уметност, култура и забава' },
science: { name: 'Наука', description: 'Научни откритија и технологија' }, science: { name: 'Наука', description: 'Научни откритија и технологија' },
@ -186,8 +170,10 @@ export class StrapiService {
// If URL is relative, prepend Strapi base URL // If URL is relative, prepend Strapi base URL
if (imageUrl.startsWith('/')) { if (imageUrl.startsWith('/')) {
// Use public URL for frontend access // Convert Docker service URL to localhost for frontend access
return `${this.strapiPublicUrl}${imageUrl}`; // Backend uses http://cms:1337 internally, but frontend needs http://localhost:1337
const frontendStrapiUrl = this.strapiUrl.replace('cms:', 'localhost:');
return `${frontendStrapiUrl}${imageUrl}`;
} }
return imageUrl; return imageUrl;
@ -212,8 +198,10 @@ export class StrapiService {
// If URL is relative, prepend Strapi base URL // If URL is relative, prepend Strapi base URL
if (imageUrl.startsWith('/')) { if (imageUrl.startsWith('/')) {
// Use public URL for frontend access // Convert Docker service URL to localhost for frontend access
return `${this.strapiPublicUrl}${imageUrl}`; // Backend uses http://cms:1337 internally, but frontend needs http://localhost:1337
const frontendStrapiUrl = this.strapiUrl.replace('cms:', 'localhost:');
return `${frontendStrapiUrl}${imageUrl}`;
} }
return imageUrl; return imageUrl;
@ -249,15 +237,11 @@ export class StrapiService {
} }
} }
// Generate slug if missing or null
const slug =
strapiArticle.slug || this.generateSlug(strapiArticle.title);
const articleData: Partial<CreateArticleDto> = { const articleData: Partial<CreateArticleDto> = {
title: strapiArticle.title, title: strapiArticle.title,
excerpt: strapiArticle.description || '', excerpt: strapiArticle.description,
content: strapiArticle.content, content: strapiArticle.content,
slug, slug: strapiArticle.slug,
status: strapiArticle.publishedAt status: strapiArticle.publishedAt
? ArticleStatus.PUBLISHED ? ArticleStatus.PUBLISHED
: ArticleStatus.DRAFT, : ArticleStatus.DRAFT,
@ -340,14 +324,11 @@ export class StrapiService {
} }
} }
// Generate slug if missing or null
const slug = strapiArticle.slug || this.generateSlug(strapiArticle.title);
const articleData: Partial<CreateArticleDto> = { const articleData: Partial<CreateArticleDto> = {
title: strapiArticle.title, title: strapiArticle.title,
excerpt: strapiArticle.description || '', excerpt: strapiArticle.description,
content: strapiArticle.content, content: strapiArticle.content,
slug, slug: strapiArticle.slug,
status, status,
tags: [], tags: [],
featuredImage: imageUrl, featuredImage: imageUrl,

View File

@ -1,20 +0,0 @@
# Server
HOST=0.0.0.0
PORT=1337
# Secrets (these should be overridden by docker env vars)
APP_KEYS=tobereplaced
API_TOKEN_SALT=tobereplaced
ADMIN_JWT_SECRET=tobereplaced
TRANSFER_TOKEN_SALT=tobereplaced
JWT_SECRET=tobereplaced
# Database (these MUST be overridden by docker env vars)
DATABASE_CLIENT=postgres
DATABASE_HOST=postgres-cms
DATABASE_PORT=5432
DATABASE_NAME=placebo_cms_db
DATABASE_USERNAME=placebo_user
DATABASE_PASSWORD=placebo_pass
DATABASE_SSL=false

View File

@ -6,10 +6,11 @@ FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Copy package files # Copy package files
COPY package.json package-lock.json* ./ COPY package*.json ./
COPY package-lock.json* ./
# Install dependencies # Install dependencies
RUN npm install --legacy-peer-deps RUN npm ci --only=production
# Copy source code # Copy source code
COPY . . COPY . .
@ -17,56 +18,40 @@ COPY . .
# Build Strapi # Build Strapi
RUN npm run build RUN npm run build
# Prune devDependencies after build (suppress warning)
RUN npm prune --omit=dev
# Production stage # Production stage
FROM node:20-alpine FROM node:20-alpine
WORKDIR /app WORKDIR /app
# Install su-exec for user switching in entrypoint
RUN apk add --no-cache su-exec
# Create non-root user # Create non-root user
RUN addgroup -g 1001 -S nodejs && \ RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 adduser -S nodejs -u 1001
# Install SQLite for development (will use PostgreSQL in production)
RUN apk add --no-cache sqlite
# Copy built application from builder stage # Copy built application from builder stage
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/dist/config ./config
COPY --from=builder --chown=nodejs:nodejs /app/src ./src
COPY --from=builder --chown=nodejs:nodejs /app/public ./public COPY --from=builder --chown=nodejs:nodejs /app/public ./public
COPY --from=builder --chown=nodejs:nodejs /app/favicon.png ./favicon.png
COPY --from=builder --chown=nodejs:nodejs /app/.strapi ./.strapi
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./ COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./
# Copy entrypoint script # Copy environment configuration
COPY docker-entrypoint.sh /usr/local/bin/ COPY --chown=nodejs:nodejs .env.example .env
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create the directory structure Strapi expects for the admin build # Create data directory for SQLite
RUN mkdir -p /app/node_modules/@strapi/admin/dist/server/server && \ RUN mkdir -p /app/.tmp && \
ln -sf /app/dist/build /app/node_modules/@strapi/admin/dist/server/server/build && \ chown -R nodejs:nodejs /app/.tmp
chown -R nodejs:nodejs /app/node_modules/@strapi/admin
# Create data and database directories with proper permissions # Switch to non-root user
RUN mkdir -p /app/.tmp /app/database /app/database/migrations /app/public/uploads && \ USER nodejs
chown -R nodejs:nodejs /app
# Don't switch to nodejs user yet - entrypoint will handle it
# USER nodejs
# Health check # Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:1337/_health', (r) => {if(r.statusCode !== 200) process.exit(1)})" CMD node -e "require('http').get('http://localhost:1337/_health', (r) => {if(r.statusCode !== 200) throw new Error()})"
# Expose port # Expose port
EXPOSE 1337 EXPOSE 1337
# Use entrypoint to fix permissions on startup then switch to nodejs user
ENTRYPOINT ["docker-entrypoint.sh"]
# Start Strapi # Start Strapi
CMD ["npm", "run", "start"] CMD ["npm", "run", "start"]

View File

@ -1 +0,0 @@
ad31a55be0b5efc2d6d7b5490e8d1a31b1a3a2aecbcf99e8f65bcb44bd0189e2918388b942fb3ac7b35fd470d19d475e556489b773c68756977e452aec1ab83f34876ed76ebadafce31636d5621c66820425d1105d753cdc5452d8f3d503ddbaebf45fc6817c235e1f8eae12d118452951ee0a48691446475f7ffc6a72fd6ffb

View File

@ -17,9 +17,4 @@ export default ({ env }) => ({
nps: env.bool('FLAG_NPS', true), nps: env.bool('FLAG_NPS', true),
promoteEE: env.bool('FLAG_PROMOTE_EE', true), promoteEE: env.bool('FLAG_PROMOTE_EE', true),
}, },
// Specify the build directory path for production
path: env('ADMIN_PATH', '/admin'),
build: {
backend: env('PUBLIC_URL', 'https://cms.placebo.mk'),
},
}); });

View File

@ -3,51 +3,58 @@ import path from 'path';
export default ({ env }) => { export default ({ env }) => {
const client = env('DATABASE_CLIENT', 'sqlite'); const client = env('DATABASE_CLIENT', 'sqlite');
console.log('=== DATABASE CONFIGURATION ==='); const connections = {
console.log('DATABASE_CLIENT:', client); mysql: {
console.log('DATABASE_HOST:', env('DATABASE_HOST', 'not-set')); connection: {
console.log('DATABASE_PORT:', env('DATABASE_PORT', 'not-set')); host: env('DATABASE_HOST', 'localhost'),
console.log('DATABASE_USERNAME:', env('DATABASE_USERNAME', 'not-set')); port: env.int('DATABASE_PORT', 3306),
console.log('DATABASE_NAME:', env('DATABASE_NAME', 'not-set')); database: env('DATABASE_NAME', 'strapi'),
console.log('DATABASE_PASSWORD:', env('DATABASE_PASSWORD') ? '***SET***' : '***NOT SET***'); user: env('DATABASE_USERNAME', 'strapi'),
console.log('DATABASE_SSL:', env('DATABASE_SSL', 'not-set')); password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
if (client === 'postgres') { key: env('DATABASE_SSL_KEY', undefined),
const connectionConfig = { cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'), host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432), port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'), database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'), user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'), password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) ? { rejectUnauthorized: false } : false, ssl: env.bool('DATABASE_SSL', false) && {
}; key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
console.log('PostgreSQL connection config:', JSON.stringify({ ca: env('DATABASE_SSL_CA', undefined),
...connectionConfig, capath: env('DATABASE_SSL_CAPATH', undefined),
password: connectionConfig.password ? `***${connectionConfig.password.length} chars***` : '***NOT SET***' cipher: env('DATABASE_SSL_CIPHER', undefined),
}, null, 2)); rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
return {
connection: {
client: 'postgres',
connection: connectionConfig,
pool: {
min: env.int('DATABASE_POOL_MIN', 2),
max: env.int('DATABASE_POOL_MAX', 10),
}, },
acquireConnectionTimeout: env.int('DATABASE_TIMEOUT', 60000), schema: env('DATABASE_SCHEMA', 'public'),
}, },
}; pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
} },
sqlite: {
console.log('Using SQLite configuration');
return {
connection: {
client: 'sqlite',
connection: { connection: {
filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', '.tmp/data.db')), filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', '.tmp/data.db')),
}, },
useNullAsDefault: true, useNullAsDefault: true,
}, },
}; };
return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
},
};
}; };

View File

@ -5,17 +5,7 @@ export default [
'strapi::cors', 'strapi::cors',
'strapi::poweredBy', 'strapi::poweredBy',
'strapi::query', 'strapi::query',
{ 'strapi::body',
name: 'strapi::body',
config: {
formLimit: '256mb', // Max form size
jsonLimit: '256mb', // Max JSON payload size
textLimit: '256mb', // Max text payload size
formidable: {
maxFileSize: 200 * 1024 * 1024, // 200MB in bytes
},
},
},
'strapi::session', 'strapi::session',
'strapi::favicon', 'strapi::favicon',
'strapi::public', 'strapi::public',

View File

@ -1,7 +1 @@
export default ({ env }) => ({ export default () => ({});
upload: {
config: {
sizeLimit: 200 * 1024 * 1024, // 200MB in bytes
},
},
});

View File

@ -1,7 +1,6 @@
export default ({ env }) => ({ export default ({ env }) => ({
host: env('HOST', '0.0.0.0'), host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337), port: env.int('PORT', 1337),
url: env('PUBLIC_URL', 'https://cms.placebo.mk'),
app: { app: {
keys: env.array('APP_KEYS'), keys: env.array('APP_KEYS'),
}, },

View File

@ -1,12 +0,0 @@
#!/bin/sh
set -e
# Ensure uploads directory exists and is writable
mkdir -p /app/public/uploads
# Fix permissions for uploads directory (needed for volume mounts)
chown -R nodejs:nodejs /app/public/uploads
chmod -R 755 /app/public/uploads
# Switch to nodejs user and execute the main command
exec su-exec nodejs "$@"

View File

@ -1,2 +0,0 @@
api token=5af45b836a0bcd065b528963e62b6d5d325117dfbf179cd5123087a17906c911fd67bcb57d92f11e869ebda27339b21aa3a7221d3dbbe79de51ef2f9e2af4dae0befe6528872ca2f68f64656ed45c7dfcacea36fdb55d1d9eb2fd9275454ac7ff8ab9acb1535f62449b3f8bd75c24803a2bd0714c637fd1d0bc819798723d999

View File

@ -1,38 +0,0 @@
/**
* Script to create an API token for backend integration
* Run this inside the CMS container if the UI doesn't work
*/
import { factories } from '@strapi/strapi';
async function createApiToken() {
const strapi = await factories.createCoreStore()();
try {
// Create API token
const tokenService = strapi.service('admin::api-token');
const token = await tokenService.create({
name: 'Backend Integration',
description: 'Token for backend to fetch articles',
type: 'read-only',
permissions: [],
lifespan: null, // Unlimited
});
console.log('✅ API Token created successfully!');
console.log('\nToken details:');
console.log('Name:', token.name);
console.log('Type:', token.type);
console.log('\nTOKEN (copy this to Coolify as STRAPI_API_TOKEN):');
console.log(token.accessKey);
console.log('\n⚠ Save this token - you won\'t see it again!');
} catch (error) {
console.error('❌ Error creating API token:', error.message);
} finally {
await strapi.destroy();
}
}
createApiToken();

View File

@ -4,8 +4,7 @@
"info": { "info": {
"singularName": "article", "singularName": "article",
"pluralName": "articles", "pluralName": "articles",
"displayName": "Article", "displayName": "article"
"description": "News articles for Placebo.mk"
}, },
"options": { "options": {
"draftAndPublish": true "draftAndPublish": true
@ -13,28 +12,33 @@
"pluginOptions": {}, "pluginOptions": {},
"attributes": { "attributes": {
"title": { "title": {
"type": "string", "type": "string"
"required": true
},
"slug": {
"type": "uid",
"targetField": "title",
"required": true
},
"description": {
"type": "text"
}, },
"content": { "content": {
"type": "richtext" "type": "richtext"
}, },
"media": {
"type": "media",
"multiple": true,
"allowedTypes": [
"images",
"files",
"videos",
"audios"
]
},
"author": { "author": {
"type": "string" "type": "string"
}, },
"img": { "img": {
"type": "media", "type": "media",
"multiple": false, "multiple": false,
"required": false, "allowedTypes": [
"allowedTypes": ["images"] "images",
"files",
"videos",
"audios"
]
}, },
"imagePosition": { "imagePosition": {
"type": "enumeration", "type": "enumeration",
@ -46,14 +50,10 @@
"enum": ["small", "medium", "large"], "enum": ["small", "medium", "large"],
"default": "medium" "default": "medium"
}, },
"media": {
"type": "media",
"multiple": true,
"required": false,
"allowedTypes": ["images", "files", "videos", "audios"]
},
"videoUrl": { "videoUrl": {
"type": "string" "type": "string",
"regex": "^(https?:\\/\\/)?(www\\.)?(youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/)[a-zA-Z0-9_-]{11}",
"default": ""
}, },
"videoPosition": { "videoPosition": {
"type": "enumeration", "type": "enumeration",
@ -61,12 +61,13 @@
"default": "inline" "default": "inline"
}, },
"videoCaption": { "videoCaption": {
"type": "string" "type": "string",
"default": ""
}, },
"category": { "category": {
"type": "enumeration", "type": "enumeration",
"enum": ["general", "sport", "art", "science"], "enum": ["sport", "art", "science"],
"default": "general", "default": "sport",
"required": true "required": true
} }
} }

View File

@ -1,7 +0,0 @@
/**
* article controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::article.article');

View File

@ -0,0 +1,7 @@
/**
* article controller
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreController('api::article.article');

View File

@ -1,7 +0,0 @@
/**
* article router
*/
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::article.article');

View File

@ -0,0 +1,7 @@
/**
* article router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::article.article');

View File

@ -1,7 +0,0 @@
/**
* article service
*/
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::article.article');

View File

@ -0,0 +1,7 @@
/**
* article service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::article.article');

View File

@ -16,9 +16,5 @@ export default {
* This gives you an opportunity to set up your data model, * This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic. * run jobs, or perform some special logic.
*/ */
async bootstrap({ strapi }) { bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {},
console.log('=== Strapi Bootstrap ===');
console.log('Available content types:', Object.keys(strapi.contentTypes || {}));
console.log('Article content type exists:', !!strapi.contentTypes['api::article.article']);
},
}; };

View File

@ -1,289 +0,0 @@
# Docker Compose for Coolify Deployment
# Deploy all services in one run
#
# Usage in Coolify:
# 1. Create new Docker Compose service
# 2. Point to this file
# 3. Set environment variables in Coolify UI
# 4. Deploy
services:
# ===========================================
# DATABASES
# ===========================================
postgres-backend:
image: postgres:16-alpine
container_name: placebo-postgres-backend
restart: unless-stopped
environment:
POSTGRES_DB: placebo_backend_db
POSTGRES_USER: placebo_user
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
volumes:
- placebo-postgres-backend-data:/var/lib/postgresql/data
expose:
- "5432"
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U placebo_user -d placebo_backend_db']
interval: 5s
timeout: 5s
retries: 10
start_period: 30s
networks:
- placebo-internal
postgres-cms:
image: postgres:16-alpine
container_name: placebo-postgres-cms
restart: unless-stopped
environment:
POSTGRES_DB: placebo_cms_db
POSTGRES_USER: placebo_user
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
volumes:
- placebo-postgres-cms-data:/var/lib/postgresql/data
expose:
- "5432"
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U placebo_user -d placebo_cms_db']
interval: 5s
timeout: 5s
retries: 10
start_period: 30s
networks:
- placebo-internal
# ===========================================
# BACKEND (NestJS API)
# ===========================================
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: placebo-backend
restart: unless-stopped
environment:
NODE_ENV: production
PORT: 3000
DATABASE_TYPE: postgres
DATABASE_HOST: postgres-backend
DATABASE_PORT: 5432
DATABASE_USERNAME: placebo_user
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_NAME: placebo_backend_db
DATABASE_SYNCHRONIZE: 'true'
DATABASE_LOGGING: 'true'
JWT_SECRET: ${JWT_SECRET}
JWT_EXPIRATION: '86400'
FRONTEND_URL: https://placebo.mk
PWA_URL: https://app.placebo.mk
STRAPI_URL: http://cms:1337
STRAPI_PUBLIC_URL: https://cms.placebo.mk
VAPID_SUBJECT: ${VAPID_SUBJECT:-mailto:contact@placebo.mk}
VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY}
VAPID_PRIVATE_KEY: ${VAPID_PRIVATE_KEY}
depends_on:
postgres-backend:
condition: service_healthy
healthcheck:
test: ['CMD', 'node', '-e', "require('http').get('http://127.0.0.1:3000/api/v1/health', (r) => {if(r.statusCode !== 200) process.exit(1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- placebo-internal
- coolify
expose:
- "3000"
labels:
- "traefik.enable=true"
# HTTP router (for Let's Encrypt challenge and redirect)
- "traefik.http.routers.backend-http.rule=Host(`api.placebo.mk`)"
- "traefik.http.routers.backend-http.entrypoints=http"
- "traefik.http.routers.backend-http.middlewares=redirect-to-https"
# HTTPS router
- "traefik.http.routers.backend.rule=Host(`api.placebo.mk`)"
- "traefik.http.routers.backend.entrypoints=https"
- "traefik.http.routers.backend.tls=true"
- "traefik.http.routers.backend.tls.certresolver=letsencrypt"
- "traefik.http.routers.backend.service=backend"
# Service
- "traefik.http.services.backend.loadbalancer.server.port=3000"
# Redirect middleware
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.permanent=true"
# ===========================================
# CMS (Strapi)
# ===========================================
cms:
build:
context: ./cms/cms
dockerfile: Dockerfile
container_name: placebo-cms
restart: unless-stopped
environment:
NODE_ENV: production
HOST: 0.0.0.0
PORT: 1337
PUBLIC_URL: https://cms.placebo.mk
BACKEND_WEBHOOK_URL: http://backend:3000
DATABASE_CLIENT: postgres
DATABASE_HOST: postgres-cms
DATABASE_PORT: '5432'
DATABASE_NAME: placebo_cms_db
DATABASE_USERNAME: placebo_user
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_SSL: 'false'
APP_KEYS: ${STRAPI_APP_KEYS}
API_TOKEN_SALT: ${STRAPI_API_TOKEN_SALT}
ADMIN_JWT_SECRET: ${STRAPI_ADMIN_JWT_SECRET}
TRANSFER_TOKEN_SALT: ${STRAPI_TRANSFER_TOKEN_SALT}
JWT_SECRET: ${STRAPI_JWT_SECRET}
ENCRYPTION_KEY: ${STRAPI_ENCRYPTION_KEY}
depends_on:
postgres-cms:
condition: service_healthy
volumes:
- placebo-cms-uploads:/app/public/uploads
healthcheck:
test: ['CMD', 'node', '-e', "require('http').get('http://127.0.0.1:1337/_health', (r) => {if(r.statusCode === 200 || r.statusCode === 204) process.exit(0); process.exit(1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks:
- placebo-internal
- coolify
expose:
- "1337"
labels:
- "traefik.enable=true"
# HTTP router (for Let's Encrypt challenge and redirect)
- "traefik.http.routers.cms-http.rule=Host(`cms.placebo.mk`)"
- "traefik.http.routers.cms-http.entrypoints=http"
- "traefik.http.routers.cms-http.middlewares=redirect-to-https"
# HTTPS router
- "traefik.http.routers.cms.rule=Host(`cms.placebo.mk`)"
- "traefik.http.routers.cms.entrypoints=https"
- "traefik.http.routers.cms.tls=true"
- "traefik.http.routers.cms.tls.certresolver=letsencrypt"
- "traefik.http.routers.cms.service=cms"
# Service configuration
- "traefik.http.services.cms.loadbalancer.server.port=1337"
- "traefik.http.services.cms.loadbalancer.passhostheader=true"
- "traefik.http.services.cms.loadbalancer.responseForwarding.flushInterval=100ms"
# Health check for service
- "traefik.http.services.cms.loadbalancer.healthcheck.path=/_health"
- "traefik.http.services.cms.loadbalancer.healthcheck.interval=30s"
- "traefik.http.services.cms.loadbalancer.healthcheck.timeout=5s"
# ===========================================
# FRONTEND (React)
# ===========================================
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
VITE_API_URL: https://api.placebo.mk/api/v1
VITE_CMS_URL: https://cms.placebo.mk
VITE_PUBLIC_POSTHOG_KEY: phc_kuDGT1kUmJmijLRjiQaKWIaU4JBdFW0aELW2hIGlBXR
VITE_PUBLIC_POSTHOG_HOST: https://eu.i.posthog.com
container_name: placebo-frontend
restart: unless-stopped
depends_on:
- backend
healthcheck:
test: ['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://127.0.0.1:80/']
interval: 30s
timeout: 10s
retries: 3
networks:
- placebo-internal
- coolify
expose:
- "80"
labels:
- "traefik.enable=true"
# HTTP router (for Let's Encrypt challenge and redirect)
- "traefik.http.routers.frontend-http.rule=Host(`placebo.mk`) || Host(`www.placebo.mk`)"
- "traefik.http.routers.frontend-http.entrypoints=http"
- "traefik.http.routers.frontend-http.middlewares=redirect-to-https"
# HTTPS router
- "traefik.http.routers.frontend.rule=Host(`placebo.mk`) || Host(`www.placebo.mk`)"
- "traefik.http.routers.frontend.entrypoints=https"
- "traefik.http.routers.frontend.tls=true"
- "traefik.http.routers.frontend.tls.certresolver=letsencrypt"
- "traefik.http.routers.frontend.service=frontend"
# Service
- "traefik.http.services.frontend.loadbalancer.server.port=80"
# ===========================================
# PWA (Progressive Web App)
# ===========================================
pwa:
build:
context: ./pwa
dockerfile: Dockerfile
args:
VITE_API_URL: https://api.placebo.mk/api/v1
VITE_CMS_URL: https://cms.placebo.mk
VITE_PUBLIC_POSTHOG_KEY: phc_kuDGT1kUmJmijLRjiQaKWIaU4JBdFW0aELW2hIGlBXR
VITE_PUBLIC_POSTHOG_HOST: https://eu.i.posthog.com
container_name: placebo-pwa
restart: unless-stopped
depends_on:
- backend
healthcheck:
test: ['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://127.0.0.1:80/']
interval: 30s
timeout: 10s
retries: 3
networks:
- placebo-internal
- coolify
expose:
- "80"
labels:
- "traefik.enable=true"
# HTTP router (for Let's Encrypt challenge and redirect)
- "traefik.http.routers.pwa-http.rule=Host(`app.placebo.mk`)"
- "traefik.http.routers.pwa-http.entrypoints=http"
- "traefik.http.routers.pwa-http.middlewares=redirect-to-https"
# HTTPS router
- "traefik.http.routers.pwa.rule=Host(`app.placebo.mk`)"
- "traefik.http.routers.pwa.entrypoints=https"
- "traefik.http.routers.pwa.tls=true"
- "traefik.http.routers.pwa.tls.certresolver=letsencrypt"
- "traefik.http.routers.pwa.service=pwa"
# Service
- "traefik.http.services.pwa.loadbalancer.server.port=80"
# ===========================================
# VOLUMES (Managed by Coolify)
# ===========================================
volumes:
placebo-postgres-backend-data:
driver: local
placebo-postgres-cms-data:
driver: local
placebo-cms-uploads:
driver: local
# ===========================================
# NETWORKS
# ===========================================
networks:
placebo-internal:
driver: bridge
coolify:
external: true

View File

@ -1,155 +0,0 @@
# Production Docker Compose for Coolify
# Each service should be deployed separately in Coolify
# This file is for reference and local testing only
version: '3.8'
services:
# PostgreSQL Database
postgres:
image: postgres:16-alpine
container_name: placebo-postgres
restart: unless-stopped
environment:
POSTGRES_DB: placebo_db
POSTGRES_USER: placebo_user
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-placebo_password}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U placebo_user -d placebo_db']
interval: 10s
timeout: 5s
retries: 5
networks:
- placebo-network
# Backend API (NestJS)
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: placebo-backend
restart: unless-stopped
environment:
NODE_ENV: production
DATABASE_TYPE: postgres
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_USERNAME: placebo_user
DATABASE_PASSWORD: ${POSTGRES_PASSWORD:-placebo_password}
DATABASE_NAME: placebo_db
DATABASE_SYNCHRONIZE: 'false'
DATABASE_LOGGING: 'false'
JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
JWT_EXPIRATION: '86400'
CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:3001}
VAPID_SUBJECT: ${VAPID_SUBJECT:-mailto:contact@placebo.mk}
VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY}
VAPID_PRIVATE_KEY: ${VAPID_PRIVATE_KEY}
ports:
- '3000:3000'
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ['CMD', 'node', '-e', "require('http').get('http://localhost:3000/health', (r) => {if(r.statusCode !== 200) process.exit(1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- placebo-network
# Frontend (React)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
VITE_API_URL: ${VITE_API_URL:-http://localhost:3000/api/v1}
VITE_CMS_URL: ${VITE_CMS_URL:-http://localhost:1337}
container_name: placebo-frontend
restart: unless-stopped
ports:
- '3001:80'
depends_on:
- backend
healthcheck:
test: ['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://localhost:80/']
interval: 30s
timeout: 10s
retries: 3
networks:
- placebo-network
# PWA (Progressive Web App)
pwa:
build:
context: ./pwa
dockerfile: Dockerfile
args:
VITE_API_URL: ${VITE_API_URL:-http://localhost:3000/api/v1}
VITE_CMS_URL: ${VITE_CMS_URL:-http://localhost:1337}
container_name: placebo-pwa
restart: unless-stopped
ports:
- '5174:80'
depends_on:
- backend
healthcheck:
test: ['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://localhost:80/']
interval: 30s
timeout: 10s
retries: 3
networks:
- placebo-network
# CMS (Strapi)
cms:
build:
context: ./cms/cms
dockerfile: Dockerfile
container_name: placebo-cms
restart: unless-stopped
environment:
NODE_ENV: production
DATABASE_CLIENT: postgres
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_NAME: placebo_cms_db
DATABASE_USERNAME: placebo_user
DATABASE_PASSWORD: ${POSTGRES_PASSWORD:-placebo_password}
DATABASE_SSL: 'false'
HOST: 0.0.0.0
PORT: 1337
APP_KEYS: ${STRAPI_APP_KEYS:-key1,key2,key3,key4}
API_TOKEN_SALT: ${STRAPI_API_TOKEN_SALT:-change-me}
ADMIN_JWT_SECRET: ${STRAPI_ADMIN_JWT_SECRET:-change-me}
TRANSFER_TOKEN_SALT: ${STRAPI_TRANSFER_TOKEN_SALT:-change-me}
JWT_SECRET: ${STRAPI_JWT_SECRET:-change-me}
ports:
- '1337:1337'
depends_on:
postgres:
condition: service_healthy
volumes:
- cms_uploads:/app/public/uploads
healthcheck:
test: ['CMD', 'node', '-e', "require('http').get('http://localhost:1337/_health', (r) => {if(r.statusCode !== 200) process.exit(1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks:
- placebo-network
volumes:
postgres_data:
driver: local
cms_uploads:
driver: local
networks:
placebo-network:
driver: bridge

View File

@ -1,61 +0,0 @@
---
name: integration-react-tanstack-router-code-based
description: >-
PostHog integration for React applications using TanStack Router with
code-based routing
metadata:
author: PostHog
version: 1.8.1
---
# PostHog integration for React with TanStack Router (code-based)
This skill helps you add PostHog analytics to React with TanStack Router (code-based) applications.
## Workflow
Follow these steps in order to complete the integration:
1. `basic-integration-1.0-begin.md` - PostHog Setup - Begin ← **Start here**
2. `basic-integration-1.1-edit.md` - PostHog Setup - Edit
3. `basic-integration-1.2-revise.md` - PostHog Setup - Revise
4. `basic-integration-1.3-conclude.md` - PostHog Setup - Conclusion
## Reference files
- `EXAMPLE.md` - React with TanStack Router (code-based) example project code
- `tanstack-start.md` - Tanstack start - docs
- `identify-users.md` - Identify users - docs
- `basic-integration-1.0-begin.md` - PostHog setup - begin
- `basic-integration-1.1-edit.md` - PostHog setup - edit
- `basic-integration-1.2-revise.md` - PostHog setup - revise
- `basic-integration-1.3-conclude.md` - PostHog setup - conclusion
The example project shows the target implementation pattern. Consult the documentation for API details.
## Key principles
- **Environment variables**: Always use environment variables for PostHog keys. Never hardcode them.
- **Minimal changes**: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
- **Match the example**: Your implementation should follow the example project's patterns as closely as possible.
## Framework guidelines
- For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
- Add analytics capture in event handlers where user actions occur, NOT in useEffect reacting to state changes
- Do NOT use useEffect for data transformation - calculate derived values during render instead
- Do NOT use useEffect to respond to user events - put that logic in the event handler itself
- Do NOT use useEffect to chain state updates - calculate all related updates together in the event handler
- Do NOT use useEffect to notify parent components - call the parent callback alongside setState in the event handler
- To reset component state when a prop changes, pass the prop as the component's key instead of using useEffect
- useEffect is ONLY for synchronizing with external systems (non-React widgets, browser APIs, network subscriptions)
- Use TanStack Router's built-in navigation events for pageview tracking instead of useEffect
- Use PostHogProvider in the root component defined in either the file-based convention (__root.tsx) or code-based convention (wherever createRootRoute() is called) so all child routes have access to the PostHog client
## Identifying users
Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` headers to maintain correlation.
## Error tracking
Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.

View File

@ -1,783 +0,0 @@
# PostHog React with TanStack Router (code-based) Example Project
Repository: https://github.com/PostHog/context-mill
Path: basics/react-tanstack-router-code-based
---
## README.md
# PostHog TanStack Router Example (Code-Based Routing)
This is a React and [TanStack Router](https://tanstack.com/router) example demonstrating PostHog integration with product analytics, session replay, and error tracking. This example uses **code-based routing** where routes are defined programmatically.
## Features
- **Product analytics**: Track user events and behaviors
- **Session replay**: Record and replay user sessions
- **Error tracking**: Capture and track errors
- **User authentication**: Demo login system with PostHog user identification
- **Client-side tracking**: Pure client-side React implementation
- **Reverse proxy**: PostHog ingestion through Vite proxy
## Getting started
### 1. Install dependencies
```bash
npm install
```
### 2. Configure environment variables
Create a `.env` file in the root directory:
```bash
VITE_PUBLIC_POSTHOG_KEY=your_posthog_project_api_key
VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
```
Get your PostHog API key from your [PostHog project settings](https://app.posthog.com/project/settings).
### 3. Run the development server
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the app.
## Project structure
```
src/
├── contexts/
│ └── AuthContext.tsx # Authentication context with PostHog integration
├── main.tsx # App entry point with all routes defined in code
├── reportWebVitals.ts # Performance monitoring
└── styles.css # Global styles
```
## Key integration points
### PostHog provider setup (main.tsx)
PostHog is initialized using `PostHogProvider` from `@posthog/react`. The provider wraps the entire app in the root route component:
```typescript
import { PostHogProvider } from '@posthog/react'
import { createRootRoute } from '@tanstack/react-router'
const rootRoute = createRootRoute({
component: RootComponent,
})
function RootComponent() {
return (
<PostHogProvider
apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY!}
options={{
api_host: '/ingest',
ui_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.posthog.com',
defaults: '2026-01-30',
capture_exceptions: true,
debug: import.meta.env.DEV,
}}
>
{/* your app */}
</PostHogProvider>
)
}
```
### User identification (contexts/AuthContext.tsx)
```typescript
import { usePostHog } from '@posthog/react'
const posthog = usePostHog()
posthog.identify(username, {
username: username,
})
```
### Event tracking (main.tsx - BurritoPage)
```typescript
import { usePostHog } from '@posthog/react'
const posthog = usePostHog()
posthog.capture('burrito_considered', {
total_considerations: count,
username: username,
})
```
### Error tracking (main.tsx - ProfilePage)
```typescript
posthog.captureException(error)
```
## TanStack Router details
This example uses TanStack Router with **code-based routing**. Key details:
1. **Client-side only**: No server-side logic, no API routes, no posthog-node
2. **Code-based routing**: All routes defined in `main.tsx` using `createRoute()` and `createRootRoute()`
3. **Manual route tree**: Routes connected with `addChildren()` method
4. **Standard hooks**: Uses `useNavigate()` from @tanstack/react-router
5. **Vite proxy**: Uses Vite's proxy config for PostHog calls
6. **Environment variables**: Uses `import.meta.env.VITE_*`
7. **PostHog provider**: Uses `PostHogProvider` from `@posthog/react` in root route
### Code-based vs File-based routing
This example demonstrates **code-based routing**, where routes are defined programmatically:
```typescript
import { createRoute, createRootRoute, createRouter } from '@tanstack/react-router'
const rootRoute = createRootRoute({ component: RootComponent })
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: Home,
})
const burritoRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/burrito',
component: BurritoPage,
})
const routeTree = rootRoute.addChildren([indexRoute, burritoRoute])
const router = createRouter({ routeTree })
```
For file-based routing (auto-generated from file structure), see the `react-tanstack-router-file-based` example.
## Learn more
- [PostHog Documentation](https://posthog.com/docs)
- [TanStack Router Documentation](https://tanstack.com/router)
- [TanStack Router Code-Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing)
- [PostHog React Integration Guide](https://posthog.com/docs/libraries/react)
---
## .env.example
```example
VITE_PUBLIC_POSTHOG_KEY=<ph_project_api_key>
VITE_PUBLIC_POSTHOG_HOST=<ph_client_api_host>
```
---
## .prettierignore
```
package-lock.json
pnpm-lock.yaml
yarn.lock
```
---
## index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="React TanStack Router code-based routing example"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<title>React TanStack Router - Code-Based</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
```
---
## prettier.config.js
```js
// @ts-check
/** @type {import('prettier').Config} */
const config = {
semi: false,
singleQuote: true,
trailingComma: "all",
};
export default config;
```
---
## public/robots.txt
```txt
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
```
---
## src/contexts/AuthContext.tsx
```tsx
import { createContext, useContext, useState, type ReactNode } from 'react';
import { usePostHog } from '@posthog/react';
interface User {
username: string;
burritoConsiderations: number;
}
interface AuthContextType {
user: User | null;
login: (username: string, password: string) => Promise<boolean>;
logout: () => void;
incrementBurritoConsiderations: () => void;
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
const users: Map<string, User> = new Map();
export function AuthProvider({ children }: { children: ReactNode }) {
// Use lazy initializer to read from localStorage only once on mount
const [user, setUser] = useState<User | null>(() => {
if (typeof window === 'undefined') return null;
const storedUsername = localStorage.getItem('currentUser');
if (storedUsername) {
const existingUser = users.get(storedUsername);
if (existingUser) {
return existingUser;
}
}
return null;
});
const posthog = usePostHog();
const login = async (username: string, password: string): Promise<boolean> => {
if (!username || !password) {
return false;
}
// Get or create user in local map
let user = users.get(username);
const isNewUser = !user;
if (!user) {
user = { username, burritoConsiderations: 0 };
users.set(username, user);
}
setUser(user);
localStorage.setItem('currentUser', username);
// Identify user in PostHog using username as distinct ID
posthog.identify(username, {
username: username,
isNewUser: isNewUser,
});
// Capture login event
posthog.capture('user_logged_in', {
username: username,
isNewUser: isNewUser,
});
return true;
};
const logout = () => {
// Capture logout event before resetting
posthog.capture('user_logged_out');
posthog.reset();
setUser(null);
localStorage.removeItem('currentUser');
};
const incrementBurritoConsiderations = () => {
if (user) {
user.burritoConsiderations++;
users.set(user.username, user);
setUser({ ...user });
}
};
return (
<AuthContext.Provider value={{ user, login, logout, incrementBurritoConsiderations }}>
{children}
</AuthContext.Provider>
);
}
export function useAuth() {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
}
```
---
## src/main.tsx
```tsx
import { StrictMode, useState } from 'react'
import ReactDOM from 'react-dom/client'
import {
Link,
Outlet,
RouterProvider,
createRootRoute,
createRoute,
createRouter,
useNavigate,
} from '@tanstack/react-router'
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
import { TanStackDevtools } from '@tanstack/react-devtools'
import { PostHogProvider, usePostHog } from '@posthog/react'
import { AuthProvider, useAuth } from './contexts/AuthContext'
import './styles.css'
import reportWebVitals from './reportWebVitals'
// ============================================================================
// Root Route
// ============================================================================
const rootRoute = createRootRoute({
component: RootComponent,
})
function RootComponent() {
return (
<PostHogProvider
apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY!}
options={{
api_host: '/ingest',
ui_host:
import.meta.env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.posthog.com',
defaults: '2026-01-30',
capture_exceptions: true,
debug: import.meta.env.DEV,
}}
>
<AuthProvider>
<Header />
<main>
<Outlet />
</main>
<TanStackDevtools
config={{
position: 'bottom-right',
}}
plugins={[
{
name: 'Tanstack Router',
render: <TanStackRouterDevtoolsPanel />,
},
]}
/>
</AuthProvider>
</PostHogProvider>
)
}
// ============================================================================
// Header Component
// ============================================================================
function Header() {
const { user, logout } = useAuth()
return (
<header className="header">
<div className="header-container">
<nav>
<Link to="/">Home</Link>
{user && (
<>
<Link to="/burrito">Burrito Consideration</Link>
<Link to="/profile">Profile</Link>
</>
)}
</nav>
<div className="user-section">
{user ? (
<>
<span>Welcome, {user.username}!</span>
<button onClick={logout} className="btn-logout">
Logout
</button>
</>
) : (
<span>Not logged in</span>
)}
</div>
</div>
</header>
)
}
// ============================================================================
// Index Route (Home Page)
// ============================================================================
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: Home,
})
function Home() {
const { user, login } = useAuth()
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError('')
try {
const success = await login(username, password)
if (success) {
setUsername('')
setPassword('')
} else {
setError('Please provide both username and password')
}
} catch (err) {
console.error('Login failed:', err)
setError('An error occurred during login')
}
}
if (user) {
return (
<div className="container">
<h1>Welcome back, {user.username}!</h1>
<p>You are now logged in. Feel free to explore:</p>
<ul>
<li>Consider the potential of burritos</li>
<li>View your profile and statistics</li>
</ul>
</div>
)
}
return (
<div className="container">
<h1>Welcome to Burrito Consideration App</h1>
<p>Please sign in to begin your burrito journey</p>
<form onSubmit={handleSubmit} className="form">
<div className="form-group">
<label htmlFor="username">Username:</label>
<input
type="text"
id="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Enter any username"
/>
</div>
<div className="form-group">
<label htmlFor="password">Password:</label>
<input
type="password"
id="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter any password"
/>
</div>
{error && <p className="error">{error}</p>}
<button type="submit" className="btn-primary">
Sign In
</button>
</form>
<p className="note">
Note: This is a demo app. Use any username and password to sign in.
</p>
</div>
)
}
// ============================================================================
// Burrito Route
// ============================================================================
const burritoRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/burrito',
component: BurritoPage,
})
function BurritoPage() {
const { user, incrementBurritoConsiderations } = useAuth()
const navigate = useNavigate()
const posthog = usePostHog()
const [hasConsidered, setHasConsidered] = useState(false)
// Redirect to home if not logged in
if (!user) {
navigate({ to: '/' })
return null
}
const handleConsideration = () => {
incrementBurritoConsiderations()
setHasConsidered(true)
setTimeout(() => setHasConsidered(false), 2000)
// Capture burrito consideration event
console.log('posthog', posthog)
posthog.capture('burrito_considered', {
total_considerations: user.burritoConsiderations + 1,
username: user.username,
})
}
return (
<div className="container">
<h1>Burrito consideration zone</h1>
<p>Take a moment to truly consider the potential of burritos.</p>
<div style={{ textAlign: 'center' }}>
<button onClick={handleConsideration} className="btn-burrito">
I have considered the burrito potential
</button>
{hasConsidered && (
<p className="success">
Thank you for your consideration! Count: {user.burritoConsiderations}
</p>
)}
</div>
<div className="stats">
<h3>Consideration stats</h3>
<p>Total considerations: {user.burritoConsiderations}</p>
</div>
</div>
)
}
// ============================================================================
// Profile Route
// ============================================================================
const profileRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/profile',
component: ProfilePage,
})
function ProfilePage() {
const { user } = useAuth()
const navigate = useNavigate()
const posthog = usePostHog()
// Redirect to home if not logged in
if (!user) {
navigate({ to: '/' })
return null
}
const triggerTestError = () => {
try {
throw new Error('Test error for PostHog error tracking')
} catch (err) {
posthog.captureException(err)
console.error('Captured error:', err)
alert('Error captured and sent to PostHog!')
}
}
return (
<div className="container">
<h1>User Profile</h1>
<div className="stats">
<h2>Your Information</h2>
<p>
<strong>Username:</strong> {user.username}
</p>
<p>
<strong>Burrito Considerations:</strong> {user.burritoConsiderations}
</p>
</div>
<div style={{ marginTop: '2rem' }}>
<button
onClick={triggerTestError}
className="btn-primary"
style={{ backgroundColor: '#dc3545' }}
>
Trigger Test Error (for PostHog)
</button>
</div>
<div style={{ marginTop: '2rem' }}>
<h3>Your Burrito Journey</h3>
{user.burritoConsiderations === 0 ? (
<p>
You haven't considered any burritos yet. Visit the Burrito
Consideration page to start!
</p>
) : user.burritoConsiderations === 1 ? (
<p>You've considered the burrito potential once. Keep going!</p>
) : user.burritoConsiderations < 5 ? (
<p>You're getting the hang of burrito consideration!</p>
) : user.burritoConsiderations < 10 ? (
<p>You're becoming a burrito consideration expert!</p>
) : (
<p>You are a true burrito consideration master!</p>
)}
</div>
</div>
)
}
// ============================================================================
// Route Tree & Router Setup
// ============================================================================
const routeTree = rootRoute.addChildren([indexRoute, burritoRoute, profileRoute])
const router = createRouter({
routeTree,
context: {},
defaultPreload: 'intent',
scrollRestoration: true,
defaultStructuralSharing: true,
defaultPreloadStaleTime: 0,
})
// Register the router instance for type safety
declare module '@tanstack/react-router' {
interface Register {
router: typeof router
}
}
// ============================================================================
// Render the App
// ============================================================================
const rootElement = document.getElementById('app')
if (rootElement && !rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
root.render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
)
}
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals()
```
---
## src/reportWebVitals.ts
```ts
const reportWebVitals = (onPerfEntry?: () => void) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {
onCLS(onPerfEntry)
onINP(onPerfEntry)
onFCP(onPerfEntry)
onLCP(onPerfEntry)
onTTFB(onPerfEntry)
})
}
}
export default reportWebVitals
```
---
## vite.config.ts
```ts
import { defineConfig, loadEnv } from 'vite'
import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { fileURLToPath, URL } from 'node:url'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [viteReact(), tailwindcss()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
proxy: {
'/ingest': {
target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/ingest/, ''),
},
},
},
}
})
```
---

View File

@ -1,43 +0,0 @@
---
title: PostHog Setup - Begin
description: Start the event tracking setup process by analyzing the project and creating an event tracking plan
---
We're making an event tracking plan for this project.
Before proceeding, find any existing `posthog.capture()` code. Make note of event name formatting.
From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events. Also look for additional files related to login that could be used for identifying users, along with error handling. Read the files. If a file is already well-covered by PostHog events, replace it with another option. Do not spawn subagents.
Look for opportunities to track client-side events.
**IMPORTANT: Server-side events are REQUIRED** if the project includes any instrumentable server-side code. If the project has API routes (e.g., `app/api/**/route.ts`) or Server Actions, you MUST include server-side events for critical business operations like:
- Payment/checkout completion
- Webhook handlers
- Authentication endpoints
Do not skip server-side events - they capture actions that cannot be tracked client-side.
Create a new file with a JSON array at the root of the project: .posthog-events.json. It should include one object for each event we want to add: event name, event description, and the file path we want to place the event in. If events already exist, don't duplicate them; supplement them.
Track actions only, not pageviews. These can be captured automatically. Exceptions can be made for "viewed"-type events that correspond to the top of a conversion funnel.
As you review files, make an internal note of opportunities to identify users and catch errors. We'll need them for the next step.
## Status
Before beginning a phase of the setup, you will send a status message with the exact prefix '[STATUS]', as in:
[STATUS] Checking project structure.
Status to report in this phase:
- Checking project structure
- Verifying PostHog dependencies
- Generating events based on project
---
**Upon completion, continue with:** [basic-integration-1.1-edit.md](basic-integration-1.1-edit.md)

View File

@ -1,37 +0,0 @@
---
title: PostHog Setup - Edit
description: Implement PostHog event tracking in the identified files, following best practices and the example project
---
For each of the files and events noted in .posthog-events.json, make edits to capture events using PostHog. Make sure to set up any helper files needed. Carefully examine the included example project code: your implementation should match it as closely as possible. Do not spawn subagents.
Use environment variables for PostHog keys. Do not hardcode PostHog keys.
If a file already has existing integration code for other tools or services, don't overwrite or remove that code. Place PostHog code below it.
For each event, add useful properties, and use your access to the PostHog source code to ensure correctness. You also have access to documentation about creating new events with PostHog. Consider this documentation carefully and follow it closely before adding events. Your integration should be based on documented best practices. Carefully consider how the user project's framework version may impact the correct PostHog integration approach.
Remember that you can find the source code for any dependency in the node_modules directory. This may be necessary to properly populate property names. There are also example project code files available via the PostHog MCP; use these for reference.
Where possible, add calls for PostHog's identify() function on the client side upon events like logins and signups. Use the contents of login and signup forms to identify users on submit. If there is server-side code, pass the client-side session and distinct ID to the server-side code to identify the user. On the server side, make sure events have a matching distinct ID where relevant.
It's essential to do this in both client code and server code, so that user behavior from both domains is easy to correlate.
You should also add PostHog exception capture error tracking to these files where relevant.
Remember: Do not alter the fundamental architecture of existing files. Make your additions minimal and targeted.
Remember the documentation and example project resources you were provided at the beginning. Read them now.
## Status
Status to report in this phase:
- Inserting PostHog capture code
- A status message for each file whose edits you are planning, including a high level summary of changes
- A status message for each file you have edited
---
**Upon completion, continue with:** [basic-integration-1.2-revise.md](basic-integration-1.2-revise.md)

View File

@ -1,22 +0,0 @@
---
title: PostHog Setup - Revise
description: Review and fix any errors in the PostHog integration implementation
---
Check the project for errors. Read the package.json file for any type checking or build scripts that may provide input about what to fix. Remember that you can find the source code for any dependency in the node_modules directory. Do not spawn subagents.
Ensure that any components created were actually used.
Once all other tasks are complete, run any linter or prettier-like scripts found in the package.json, but ONLY on the files you have edited or created during this session. Do not run formatting or linting across the entire project's codebase.
## Status
Status to report in this phase:
- Finding and correcting errors
- Report details of any errors you fix
- Linting, building and prettying
---
**Upon completion, continue with:** [basic-integration-1.3-conclude.md](basic-integration-1.3-conclude.md)

View File

@ -1,38 +0,0 @@
---
title: PostHog Setup - Conclusion
description: Review and fix any errors in the PostHog integration implementation
---
Use the PostHog MCP to create a new dashboard named "Analytics basics" based on the events created here. Make sure to use the exact same event names as implemented in the code. Populate it with up to five insights, with special emphasis on things like conversion funnels, churn events, and other business critical insights.
Search for a file called `.posthog-events.json` and read it for available events. Do not spawn subagents.
Create the file posthog-setup-report.md. It should include a summary of the integration edits, a table with the event names, event descriptions, and files where events were added, along with a list of links for the dashboard and insights created. Follow this format:
<wizard-report>
# PostHog post-wizard report
The wizard has completed a deep integration of your project. [Detailed summary of changes]
[table of events/descriptions/files]
## Next steps
We've built some insights and a dashboard for you to keep an eye on user behavior, based on the events we just instrumented:
[links]
### Agent skill
We've left an agent skill folder in your project. You can use this context for further agent development when using Claude Code. This will help ensure the model provides the most up-to-date approaches for integrating PostHog.
</wizard-report>
Upon completion, remove .posthog-events.json.
## Status
Status to report in this phase:
- Configured dashboard: [insert PostHog dashboard URL]
- Created setup report: [insert full local file path]

View File

@ -1,202 +0,0 @@
# Identify users - Docs
Linking events to specific users enables you to build a full picture of how they're using your product across different sessions, devices, and platforms.
This is straightforward to do when [capturing backend events](/docs/product-analytics/capture-events?tab=Node.js.md), as you associate events to a specific user using a `distinct_id`, which is a required argument.
However, in the frontend of a [web](/docs/libraries/js/features#capturing-events.md) or [mobile app](/docs/libraries/ios#capturing-events.md), a `distinct_id` is not a required argument — PostHog's SDKs will generate an anonymous `distinct_id` for you automatically and you can capture events anonymously, provided you use the appropriate [configuration](/docs/libraries/js/features#capturing-anonymous-events.md).
To link events to specific users, call `identify`:
PostHog AI
### Web
```javascript
posthog.identify(
'distinct_id', // Replace 'distinct_id' with your user's unique identifier
{ email: 'max@hedgehogmail.com', name: 'Max Hedgehog' } // optional: set additional person properties
);
```
### Android
```kotlin
PostHog.identify(
distinctId = distinctID, // Replace 'distinctID' with your user's unique identifier
// optional: set additional person properties
userProperties = mapOf(
"name" to "Max Hedgehog",
"email" to "max@hedgehogmail.com"
)
)
```
### iOS
```swift
PostHogSDK.shared.identify("distinct_id", // Replace "distinct_id" with your user's unique identifier
userProperties: ["name": "Max Hedgehog", "email": "max@hedgehogmail.com"]) // optional: set additional person properties
```
### React Native
```jsx
posthog.identify('distinct_id', { // Replace "distinct_id" with your user's unique identifier
email: 'max@hedgehogmail.com', // optional: set additional person properties
name: 'Max Hedgehog'
})
```
### Dart
```dart
await Posthog().identify(
userId: 'distinct_id', // Replace "distinct_id" with your user's unique identifier
userProperties: {
email: "max@hedgehogmail.com", // optional: set additional person properties
name: "Max Hedgehog"
});
```
Events captured after calling `identify` are identified events and this creates a person profile if one doesn't exist already.
Due to the cost of processing them, anonymous events can be up to 4x cheaper than identified events, so it's recommended you only capture identified events when needed.
## How identify works
When a user starts browsing your website or app, PostHog automatically assigns them an **anonymous ID**, which is stored locally.
Provided you've [configured persistence](/docs/libraries/js/persistence.md) to use cookies or `localStorage`, this enables us to track anonymous users even across different sessions.
By calling `identify` with a `distinct_id` of your choice (usually the user's ID in your database, or their email), you link the anonymous ID and distinct ID together.
Thus, all past and future events made with that anonymous ID are now associated with the distinct ID.
This enables you to do things like associate events with a user from before they log in for the first time, or associate their events across different devices or platforms.
Using identify in the backend
Although you can call `identify` using our backend SDKs, it is used most in frontends. This is because there is no concept of anonymous sessions in the backend SDKs, so calling `identify` only updates person profiles.
## Best practices when using `identify`
### 1\. Call `identify` as soon as you're able to
In your frontend, you should call `identify` as soon as you're able to.
Typically, this is every time your **app loads** for the first time, and directly after your **users log in**.
This ensures that events sent during your users' sessions are correctly associated with them.
You only need to call `identify` once per session, and you should avoid calling it multiple times unnecessarily.
If you call `identify` multiple times with the same data without reloading the page in between, PostHog will ignore the subsequent calls.
### 2\. Use unique strings for distinct IDs
If two users have the same distinct ID, their data is merged and they are considered one user in PostHog. Two common ways this can happen are:
- Your logic for generating IDs does not generate sufficiently strong IDs and you can end up with a clash where 2 users have the same ID.
- There's a bug, typo, or mistake in your code leading to most or all users being identified with generic IDs like `null`, `true`, or `distinctId`.
PostHog also has built-in protections to stop the most common distinct ID mistakes.
### 3\. Reset after logout
If a user logs out on your frontend, you should call `reset()` to unlink any future events made on that device with that user.
This is important if your users are sharing a computer, as otherwise all of those users are grouped together into a single user due to shared cookies between sessions.
**We strongly recommend you call `reset` on logout even if you don't expect users to share a computer.**
You can do that like so:
PostHog AI
### Web
```javascript
posthog.reset()
```
### iOS
```swift
PostHogSDK.shared.reset()
```
### Android
```kotlin
PostHog.reset()
```
### React Native
```jsx
posthog.reset()
```
### Dart
```dart
Posthog().reset()
```
If you *also* want to reset the `device_id` so that the device will be considered a new device in future events, you can pass `true` as an argument:
Web
PostHog AI
```javascript
posthog.reset(true)
```
### 4\. Person profiles and properties
You'll notice that one of the parameters in the `identify` method is a `properties` object.
This enables you to set [person properties](/docs/product-analytics/person-properties.md).
Whenever possible, we recommend passing in all person properties you have available each time you call identify, as this ensures their person profile on PostHog is up to date.
Person properties can also be set being adding a `$set` property to a event `capture` call.
See our [person properties docs](/docs/product-analytics/person-properties.md) for more details on how to work with them and best practices.
### 5\. Use deep links between platforms
We recommend you call `identify` [as soon as you're able](#1-call-identify-as-soon-as-youre-able), typically when a user signs up or logs in.
This doesn't work if one or both platforms are unauthenticated. Some examples of such cases are:
- Onboarding and signup flows before authentication.
- Unauthenticated web pages redirecting to authenticated mobile apps.
- Authenticated web apps prompting an app download.
In these cases, you can use a [deep link](https://developer.android.com/training/app-links/deep-linking) on Android and [universal links](https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app) on iOS to identify users.
1. Use `posthog.get_distinct_id()` to get the current distinct ID. Even if you cannot call identify because the user is unauthenticated, this will return an anonymous distinct ID generated by PostHog.
2. Add the distinct ID to the deep link as query parameters, along with other properties like UTM parameters.
3. When the user is redirected to the app, parse the deep link and handle the following cases:
- The user is already authenticated on the mobile app. In this case, call [`posthog.alias()`](/docs/libraries/js/features#alias.md) with the distinct ID from the web. This associates the two distinct IDs as a single person.
- The user is unauthenticated. In this case, call [`posthog.identify()`](/docs/libraries/js/features#identifying-users.md) with the distinct ID from the web. Events will be associated with this distinct ID.
As long as you associate the distinct IDs with `posthog.identify()` or `posthog.alias()`, you can track events generated across platforms.
## Further reading
- [Identifying users docs](/docs/product-analytics/identify.md)
- [How person processing works](/docs/how-posthog-works/ingestion-pipeline#2-person-processing.md)
- [An introductory guide to identifying users in PostHog](/tutorials/identifying-users-guide.md)
### Community questions
Ask a question
### Was this page useful?
HelpfulCould be better

View File

@ -1,187 +0,0 @@
# TanStack Start - Docs
This tutorial shows how to integrate PostHog with a [TanStack Start](https://tanstack.com/start) app for both client-side and server-side analytics.
## Installation
Install the required packages:
Terminal
PostHog AI
```bash
npm install @posthog/react posthog-node
```
- `@posthog/react` - React package for our [JS Web SDK](/docs/libraries/js.md) for client-side usage
- `posthog-node` - PostHog [Node.js SDK](/docs/libraries/node.md) for server-side event capture
## Initialize PostHog on the client
Wrap your app with `PostHogProvider` in your root route with your project token, host, and other options.
src/routes/\_\_root.tsx
PostHog AI
```jsx
// src/routes/__root.tsx
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
import { PostHogProvider } from '@posthog/react'
export const Route = createRootRoute({
head: () => ({
meta: [
{ charSet: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
],
}),
shellComponent: RootDocument,
})
function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<HeadContent />
</head>
<body>
<PostHogProvider
apiKey="<ph_project_token>"
options={{
api_host: 'https://us.i.posthog.com',
defaults: '2026-01-30',
capture_exceptions: true
}}
>
{children}
</PostHogProvider>
<Scripts />
</body>
</html>
)
}
```
Once the provider is in place, PostHog automatically captures pageviews, sessions, and web vitals.
## Capture events on the client
Use the `usePostHog` hook from `@posthog/react` in any component to capture custom events:
src/routes/checkout.tsx
PostHog AI
```jsx
import { usePostHog } from '@posthog/react'
function CheckoutButton({ orderId, total }: { orderId: string; total: number }) {
const posthog = usePostHog()
const handleClick = () => {
posthog.capture('checkout_started', {
order_id: orderId,
total: total,
})
}
return <button onClick={handleClick}>Checkout</button>
}
```
### Identify users
Call `posthog.identify()` when a user logs in to link their events to a user ID:
TSX
PostHog AI
```jsx
import { usePostHog } from '@posthog/react'
function LoginForm() {
const posthog = usePostHog()
const handleLogin = async (userId: string, email: string) => {
// ... your login logic
posthog.identify(userId, {
email: email,
})
posthog.capture('user_logged_in')
}
}
```
Call `posthog.reset()` on logout to clear the identified user.
## Initialize PostHog on the server
Create a server-side PostHog client using `posthog-node`. Use a singleton pattern so you reuse the same client across requests:
src/utils/posthog-server.ts
PostHog AI
```typescript
// src/utils/posthog-server.ts
import { PostHog } from 'posthog-node'
let posthogClient: PostHog | null = null
export function getPostHogClient() {
if (!posthogClient) {
posthogClient = new PostHog(
'<ph_project_token>',
{
host: 'https://us.i.posthog.com',
flushAt: 1,
flushInterval: 0,
},
)
}
return posthogClient
}
```
## Capture events on the server
Use the server client in TanStack Start API routes to capture events server-side. Server-side capture is useful for tracking events that shouldn't be spoofable from the client, like purchases or authentication:
src/routes/api/checkout.ts
PostHog AI
```typescript
// src/routes/api/checkout.ts
import { createFileRoute } from '@tanstack/react-router'
import { json } from '@tanstack/react-start'
import { getPostHogClient } from '../../utils/posthog-server'
export const Route = createFileRoute('/api/checkout')({
server: {
handlers: {
POST: async ({ request }) => {
const body = await request.json()
const posthog = getPostHogClient()
posthog.capture({
distinctId: body.userId,
event: 'item_purchased',
properties: {
item_id: body.itemId,
price: body.price,
source: 'api',
},
})
return json({ success: true })
},
},
},
})
```
The server-side `capture` call requires a `distinctId` (the user identifier), an `event` name, and optional `properties`.
## Next steps
Installing the JS Web SDK and Node SDK means all of their functionality is available in your TanStack Start project. To learn more about this, have a look at our [JS Web SDK docs](/docs/libraries/js/usage.md) and [Node SDK docs](/docs/libraries/node.md).
### Community questions
Ask a question
### Was this page useful?
HelpfulCould be better

View File

@ -11,7 +11,3 @@ VITE_API_URL=http://localhost:3000/api/v1
# ===== COMMON ===== # ===== COMMON =====
VITE_CMS_URL=http://localhost:1337 VITE_CMS_URL=http://localhost:1337
# ===== POSTHOG ANALYTICS =====
VITE_PUBLIC_POSTHOG_KEY=phc_kuDGT1kUmJmijLRjiQaKWIaU4JBdFW0aELW2hIGlBXR
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com

2
frontend/.gitignore vendored
View File

@ -22,5 +22,3 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
.env.local
.env

View File

@ -5,23 +5,12 @@ FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Build arguments for environment variables
ARG VITE_API_URL
ARG VITE_CMS_URL
ARG VITE_PUBLIC_POSTHOG_KEY
ARG VITE_PUBLIC_POSTHOG_HOST
# Set environment variables for build
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_CMS_URL=$VITE_CMS_URL
ENV VITE_PUBLIC_POSTHOG_KEY=$VITE_PUBLIC_POSTHOG_KEY
ENV VITE_PUBLIC_POSTHOG_HOST=$VITE_PUBLIC_POSTHOG_HOST
# Copy package files # Copy package files
COPY package.json package-lock.json* ./ COPY package*.json ./
COPY package-lock.json* ./
# Install dependencies # Install dependencies
RUN npm install --legacy-peer-deps RUN npm ci
# Copy source code # Copy source code
COPY . . COPY . .
@ -32,12 +21,19 @@ RUN npm run build
# Production stage # Production stage
FROM nginx:alpine FROM nginx:alpine
# Create non-root user
RUN addgroup -g 1001 -S nginx && \
adduser -S nginx -u 1001 -G nginx
# Copy built application from builder stage # Copy built application from builder stage
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html
# Copy nginx configuration # Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
# Switch to non-root user
USER nginx
# Health check # Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1

View File

@ -1,14 +1,10 @@
<!doctype html> <!doctype html>
<html lang="mk"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://eu-assets.i.posthog.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: https:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' http://localhost:3000 http://localhost:1337 https://api.placebo.mk https://cms.placebo.mk https://eu.i.posthog.com https://eu-assets.i.posthog.com;"> <title>frontend</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
<title>Placebo.mk - Сатирични вести од Македонија</title>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

View File

@ -46,7 +46,7 @@ http {
index index.html; index index.html;
# Security headers for frontend # Security headers for frontend
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://eu-assets.i.posthog.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: https:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' http://localhost:3000 http://localhost:1337 https://api.placebo.mk https://cms.placebo.mk https://eu.i.posthog.com https://eu-assets.i.posthog.com;" always; add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' http://localhost:3000 http://localhost:1337;" always;
# Handle React Router # Handle React Router
location / { location / {
@ -60,35 +60,35 @@ http {
add_header Cache-Control "public, immutable"; add_header Cache-Control "public, immutable";
} }
# API proxy (for local dev only - in prod use public URL) # API proxy
# location /api/ { location /api/ {
# proxy_pass http://backend:3000/; proxy_pass http://backend:3000/;
# proxy_http_version 1.1; proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host; proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# proxy_read_timeout 300; proxy_read_timeout 300;
# proxy_connect_timeout 300; proxy_connect_timeout 300;
# } }
# CMS proxy (for local dev only - in prod use public URL) # CMS proxy
# location /cms/ { location /cms/ {
# proxy_pass http://cms:1337/; proxy_pass http://cms:1337/;
# proxy_http_version 1.1; proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host; proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# proxy_read_timeout 300; proxy_read_timeout 300;
# proxy_connect_timeout 300; proxy_connect_timeout 300;
# } }
# Health check endpoint # Health check endpoint
location /health { location /health {

6700
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,6 @@
"dev:reset-env": "cp -f .env.docker .env" "dev:reset-env": "cp -f .env.docker .env"
}, },
"dependencies": { "dependencies": {
"@posthog/react": "^1.8.1",
"@radix-ui/react-label": "^2.1.8", "@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-select": "^2.2.6", "@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-slot": "^1.2.4", "@radix-ui/react-slot": "^1.2.4",
@ -28,10 +27,8 @@
"@tanstack/react-query": "^5.90.14", "@tanstack/react-query": "^5.90.14",
"@tanstack/react-router": "^1.144.0", "@tanstack/react-router": "^1.144.0",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"posthog-js": "^1.356.1",
"react": "^19.2.0", "react": "^19.2.0",
"react-dom": "^19.2.4", "react-dom": "^19.2.0",
"react-icons": "^5.6.0",
"react-markdown": "^10.1.0", "react-markdown": "^10.1.0",
"remark-gfm": "^4.0.1" "remark-gfm": "^4.0.1"
}, },

View File

@ -1,47 +0,0 @@
<wizard-report>
# PostHog post-wizard report
The wizard has completed a deep integration of PostHog analytics into the Placebo.mk React (TanStack Router, code-based routing) application. Here is a summary of all changes made:
## Integration summary
- **`src/main.tsx`** — Updated `PostHogProvider` options to use a `/ingest` reverse proxy (`api_host: '/ingest'`), added `ui_host`, enabled `capture_exceptions: true` for automatic error tracking, and enabled `debug` mode in development.
- **`vite.config.ts`** — Added a Vite dev server proxy for `/ingest``VITE_PUBLIC_POSTHOG_HOST`, routing PostHog calls through the dev server to avoid ad blockers.
- **`.env` / `.env.local`** — Set `VITE_PUBLIC_POSTHOG_KEY` and `VITE_PUBLIC_POSTHOG_HOST` with the correct EU cloud values.
- **`src/contexts/AuthContext.tsx`** — Added `usePostHog()`, `posthog.identify()` on login and register (using user ID as distinct ID with username, email, role properties), `posthog.capture()` for `user_logged_in`, `user_registered`, and `user_logged_out` events, and `posthog.reset()` on logout.
- **`src/components/features/social-share/SocialShareButtons.tsx`** — Added `posthog.capture('article_shared', ...)` with platform, article ID, title, and URL properties.
- **`src/components/features/comments/ReactionButtons.tsx`** — Added `posthog.capture('article_reaction_added', ...)` with reaction type, target IDs, and target type (article/live_blog/comment).
- **`src/components/features/comments/CommentSection.tsx`** — Added `posthog.capture('comment_submitted', ...)` with article/live blog ID, target type, and comment length.
- **`src/components/admin/PushNotificationManager.tsx`** — Added `posthog.capture('push_notification_sent', ...)` with notification title, sent/failed counts, and subscriber count.
- **`src/components/features/live-blog/LiveBlogViewer.tsx`** — Added `posthog.capture('live_blog_viewed', ...)` once per mount (guarded with a ref), and `posthog.capture('live_blog_reconnected', ...)` on the Reconnect button click.
## Events instrumented
| Event name | Description | File |
|---|---|---|
| `user_logged_in` | Fired when a user successfully logs in | `src/contexts/AuthContext.tsx` |
| `user_registered` | Fired when a user successfully completes registration | `src/contexts/AuthContext.tsx` |
| `user_logged_out` | Fired when a user logs out | `src/contexts/AuthContext.tsx` |
| `article_shared` | Fired when a user shares an article on a social platform | `src/components/features/social-share/SocialShareButtons.tsx` |
| `article_reaction_added` | Fired when a user reacts (like or dislike) to an article or comment | `src/components/features/comments/ReactionButtons.tsx` |
| `comment_submitted` | Fired when a user successfully posts a comment on an article or live blog | `src/components/features/comments/CommentSection.tsx` |
| `push_notification_sent` | Fired when an admin successfully sends a push notification to all subscribers | `src/components/admin/PushNotificationManager.tsx` |
| `live_blog_viewed` | Fired when a user opens a live blog page (top of engagement funnel for live coverage) | `src/components/features/live-blog/LiveBlogViewer.tsx` |
| `live_blog_reconnected` | Fired when a user manually reconnects to a live blog stream | `src/components/features/live-blog/LiveBlogViewer.tsx` |
## Next steps
We've built some insights and a dashboard for you to keep an eye on user behavior, based on the events we just instrumented:
- 📊 **Dashboard — Analytics basics**: https://eu.posthog.com/project/133810/dashboard/546519
- 📈 **User Authentication Trends** (logins, registrations, logouts over time): https://eu.posthog.com/project/133810/insights/pxodr2zQ
- 🔽 **New User Engagement Funnel** (registration → first comment → first reaction): https://eu.posthog.com/project/133810/insights/zK5n3YKc
- 🔗 **Article Shares by Platform** (breakdown of shares per social platform): https://eu.posthog.com/project/133810/insights/pplQTyt8
- 💬 **Content Engagement Activity** (comments, reactions, and shares over time): https://eu.posthog.com/project/133810/insights/wn7cQy26
- 📡 **Live Blog Engagement** (live blog views and reconnect attempts): https://eu.posthog.com/project/133810/insights/6QtI23Hm
### Agent skill
We've left an agent skill folder in your project at `.claude/skills/posthog-integration-react-tanstack-router-code-based/`. You can use this context for further agent development when using Claude Code. This will help ensure the model provides the most up-to-date approaches for integrating PostHog.
</wizard-report>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 609 KiB

1
frontend/public/vite.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -25,8 +25,7 @@ export function ArticleTicker() {
{articles.map((article, index) => ( {articles.map((article, index) => (
<Link <Link
key={`${article.id}-${index}`} key={`${article.id}-${index}`}
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors" className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors"
> >
{article.title || 'No title'} {article.title || 'No title'}
@ -35,8 +34,7 @@ export function ArticleTicker() {
{articles.map((article, index) => ( {articles.map((article, index) => (
<Link <Link
key={`dup-${article.id}-${index}`} key={`dup-${article.id}-${index}`}
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors" className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors"
> >
{article.title || 'No title'} {article.title || 'No title'}

View File

@ -2,7 +2,6 @@ import { useState } from 'react';
import { usePushStats, useSendPushNotification } from '@/queries/push'; import { usePushStats, useSendPushNotification } from '@/queries/push';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Bell, Send, Users, AlertCircle, CheckCircle } from 'lucide-react'; import { Bell, Send, Users, AlertCircle, CheckCircle } from 'lucide-react';
import { usePostHog } from '@posthog/react';
export function PushNotificationManager() { export function PushNotificationManager() {
const [title, setTitle] = useState(''); const [title, setTitle] = useState('');
@ -12,7 +11,6 @@ export function PushNotificationManager() {
const [result, setResult] = useState<{ sent: number; failed: number } | null>( const [result, setResult] = useState<{ sent: number; failed: number } | null>(
null, null,
); );
const posthog = usePostHog();
const { data: stats, isLoading: loadingStats } = usePushStats(); const { data: stats, isLoading: loadingStats } = usePushStats();
const sendMutation = useSendPushNotification(); const sendMutation = useSendPushNotification();
@ -29,13 +27,6 @@ export function PushNotificationManager() {
setResult(result); setResult(result);
setShowSuccess(true); setShowSuccess(true);
setTimeout(() => setShowSuccess(false), 5000); setTimeout(() => setShowSuccess(false), 5000);
posthog.capture('push_notification_sent', {
notification_title: title.trim(),
has_url: !!url.trim(),
sent_count: result.sent,
failed_count: result.failed,
total_subscribers: stats?.totalSubscribers,
});
} catch (error) { } catch (error) {
console.error('Failed to send notification:', error); console.error('Failed to send notification:', error);
} }

View File

@ -5,7 +5,6 @@ import { Button } from '../../ui/button';
import { Textarea } from '../../ui/textarea'; import { Textarea } from '../../ui/textarea';
import { Card, CardContent } from '../../ui/card'; import { Card, CardContent } from '../../ui/card';
import { CommentItem } from './CommentItem'; import { CommentItem } from './CommentItem';
import { usePostHog } from '@posthog/react';
interface CommentSectionProps { interface CommentSectionProps {
articleId?: string; articleId?: string;
@ -16,7 +15,6 @@ export function CommentSection({ articleId, liveBlogId }: CommentSectionProps) {
const { isAuthenticated } = useAuth(); const { isAuthenticated } = useAuth();
const [newComment, setNewComment] = useState(''); const [newComment, setNewComment] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
const posthog = usePostHog();
const { data: commentsData, isLoading } = useComments({ const { data: commentsData, isLoading } = useComments({
articleId, articleId,
@ -40,12 +38,6 @@ export function CommentSection({ articleId, liveBlogId }: CommentSectionProps) {
articleId, articleId,
liveBlogId, liveBlogId,
}); });
posthog.capture('comment_submitted', {
article_id: articleId,
live_blog_id: liveBlogId,
target_type: liveBlogId ? 'live_blog' : 'article',
comment_length: newComment.trim().length,
});
setNewComment(''); setNewComment('');
} catch (error) { } catch (error) {
console.error('Failed to post comment:', error); console.error('Failed to post comment:', error);

View File

@ -3,7 +3,6 @@ import { useAuth } from '../../../contexts/AuthContext';
import { useReactionCounts, useUserReaction, useAddReaction } from '../../../queries/comments'; import { useReactionCounts, useUserReaction, useAddReaction } from '../../../queries/comments';
import { Button } from '../../ui/button'; import { Button } from '../../ui/button';
import { ThumbsUp, ThumbsDown } from 'lucide-react'; import { ThumbsUp, ThumbsDown } from 'lucide-react';
import { usePostHog } from '@posthog/react';
interface ReactionButtonsProps { interface ReactionButtonsProps {
articleId?: string; articleId?: string;
@ -19,7 +18,6 @@ export function ReactionButtons({
compact = false compact = false
}: ReactionButtonsProps) { }: ReactionButtonsProps) {
const { isAuthenticated } = useAuth(); const { isAuthenticated } = useAuth();
const posthog = usePostHog();
const { data: counts } = useReactionCounts(articleId, liveBlogId, commentId); const { data: counts } = useReactionCounts(articleId, liveBlogId, commentId);
const { data: userReaction } = useUserReaction(articleId, liveBlogId, commentId); const { data: userReaction } = useUserReaction(articleId, liveBlogId, commentId);
@ -40,13 +38,6 @@ export function ReactionButtons({
liveBlogId, liveBlogId,
commentId, commentId,
}); });
posthog.capture('article_reaction_added', {
reaction_type: type,
article_id: articleId,
live_blog_id: liveBlogId,
comment_id: commentId,
target_type: commentId ? 'comment' : liveBlogId ? 'live_blog' : 'article',
});
} catch (error) { } catch (error) {
console.error('Failed to add reaction:', error); console.error('Failed to add reaction:', error);
} }
@ -90,7 +81,7 @@ export function ReactionButtons({
className="gap-2" className="gap-2"
> >
<ThumbsUp className="w-4 h-4" /> <ThumbsUp className="w-4 h-4" />
<span>Ми се допаѓа</span> <span>Допаѓа ми</span>
{likes > 0 && ( {likes > 0 && (
<span className="ml-1 bg-primary/20 px-2 py-0.5 rounded-full text-xs"> <span className="ml-1 bg-primary/20 px-2 py-0.5 rounded-full text-xs">
{likes} {likes}

View File

@ -5,7 +5,6 @@ import type { LiveBlogUpdate as ApiLiveBlogUpdate } from '@/lib/api';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { usePostHog } from '@posthog/react';
interface LiveBlogViewerProps { interface LiveBlogViewerProps {
slug: string; slug: string;
@ -16,8 +15,6 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
const [autoScroll, setAutoScroll] = useState(true); const [autoScroll, setAutoScroll] = useState(true);
const [newUpdatesCount, setNewUpdatesCount] = useState(0); const [newUpdatesCount, setNewUpdatesCount] = useState(0);
const [isScrolledUp, setIsScrolledUp] = useState(false); const [isScrolledUp, setIsScrolledUp] = useState(false);
const posthog = usePostHog();
const hasTrackedView = useRef(false);
const updatesContainerRef = useRef<HTMLDivElement>(null); const updatesContainerRef = useRef<HTMLDivElement>(null);
const lastUpdateCountRef = useRef(0); const lastUpdateCountRef = useRef(0);
@ -108,19 +105,6 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
} }
}, [updatesData, scrollToBottom, isScrolledUp]); }, [updatesData, scrollToBottom, isScrolledUp]);
// Track live blog view once data is loaded
useEffect(() => {
if (liveBlog && !hasTrackedView.current) {
hasTrackedView.current = true;
posthog.capture('live_blog_viewed', {
live_blog_id: liveBlog.id,
live_blog_slug: slug,
live_blog_title: liveBlog.title,
live_blog_status: liveBlog.status,
});
}
}, [liveBlog, slug, posthog]);
if (blogLoading) { if (blogLoading) {
return ( return (
<Card className={cn('w-full max-w-4xl mx-auto', className)}> <Card className={cn('w-full max-w-4xl mx-auto', className)}>
@ -181,12 +165,12 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
isConnected ? 'bg-green-500' : 'bg-red-500' isConnected ? 'bg-green-500' : 'bg-red-500'
)} /> )} />
<span> <span>
{isConnected ? 'Поврзано' : `Се поврзува... (${reconnectAttempts})`} {isConnected ? 'Connected' : `Reconnecting... (${reconnectAttempts})`}
</span> </span>
</div> </div>
)} )}
<span>{liveBlog.viewCount || 0} прегледи</span> <span>{liveBlog.viewCount} views</span>
<span>{updates.length} ажурирања</span> <span>{updates.length} updates</span>
</div> </div>
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
@ -195,20 +179,13 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
size="sm" size="sm"
onClick={handleAutoScrollToggle} onClick={handleAutoScrollToggle}
> >
{autoScroll ? 'Авто-скрол ВКЛУЧЕН' : 'Авто-скрол ИСКЛУЧЕН'} {autoScroll ? 'Auto-scroll ON' : 'Auto-scroll OFF'}
</Button> </Button>
{!isConnected && ( {!isConnected && (
<Button <Button
variant="outline" variant="outline"
size="sm" size="sm"
onClick={() => { onClick={connect}
connect();
posthog.capture('live_blog_reconnected', {
live_blog_id: liveBlog.id,
live_blog_slug: slug,
reconnect_attempts: reconnectAttempts,
});
}}
> >
Reconnect Reconnect
</Button> </Button>
@ -246,16 +223,8 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
</div> </div>
) : ( ) : (
<div className="space-y-4"> <div className="space-y-4">
{updates.map((update, index) => ( {updates.map((update) => (
<div <LiveBlogUpdate key={update.id} update={update} />
key={update.id}
className={cn(
'flex',
index % 2 === 0 ? 'justify-start' : 'justify-end'
)}
>
<LiveBlogUpdate update={update} alignRight={index % 2 !== 0} />
</div>
))} ))}
{updatesLoading && ( {updatesLoading && (
<div className="animate-pulse"> <div className="animate-pulse">
@ -286,19 +255,16 @@ export function LiveBlogViewer({ slug, className }: LiveBlogViewerProps) {
interface LiveBlogUpdateProps { interface LiveBlogUpdateProps {
update: ApiLiveBlogUpdate; update: ApiLiveBlogUpdate;
alignRight?: boolean;
} }
function LiveBlogUpdate({ update, alignRight = false }: LiveBlogUpdateProps) { function LiveBlogUpdate({ update }: LiveBlogUpdateProps) {
const isPinned = update.isPinned; const isPinned = update.isPinned;
return ( return (
<div <div
className={cn( className={cn(
'relative p-4 rounded-lg border max-w-[80%]', 'relative p-4 rounded-lg border',
isPinned && 'border-primary bg-primary/5', isPinned && 'border-primary bg-primary/5'
!isPinned && alignRight && 'bg-accent/10 border-accent/20',
!isPinned && !alignRight && 'bg-muted/50 border-muted'
)} )}
> >
{isPinned && ( {isPinned && (

View File

@ -31,7 +31,7 @@ export function PinnedLiveBlogSidebar({
<CardHeader> <CardHeader>
<CardTitle className="text-lg flex items-center gap-2"> <CardTitle className="text-lg flex items-center gap-2">
<Pin className="w-4 h-4" /> <Pin className="w-4 h-4" />
Во живо Pinned Live Blogs
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
@ -204,11 +204,11 @@ export function PinnedLiveBlogSidebar({
<div className="mt-2 flex items-center gap-3 text-xs text-muted-foreground"> <div className="mt-2 flex items-center gap-3 text-xs text-muted-foreground">
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<MessageSquare className="w-3 h-3" /> <MessageSquare className="w-3 h-3" />
<span>{blog.updates?.length || 0} ажурирања</span> <span>{blog.updates?.length || 0} updates</span>
</div> </div>
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<Eye className="w-3 h-3" /> <Eye className="w-3 h-3" />
<span>{blog.viewCount || 0} прегледи</span> <span>{blog.viewCount} views</span>
</div> </div>
</div> </div>
</Link> </Link>

View File

@ -4,11 +4,12 @@ import { type SharePlatform, getPlatformLabel } from '@/lib/social-utils';
import { import {
Facebook, Facebook,
Twitter, Twitter,
MessageCircle,
Send, Send,
Mail,
Link, Link,
Share2 Share2
} from 'lucide-react'; } from 'lucide-react';
import { FaInstagram, FaTiktok } from 'react-icons/fa';
interface ShareButtonProps { interface ShareButtonProps {
platform: SharePlatform; platform: SharePlatform;
@ -51,12 +52,12 @@ export function ShareButton({
return Facebook; return Facebook;
case 'twitter': case 'twitter':
return Twitter; return Twitter;
case 'instagram': case 'whatsapp':
return FaInstagram; return MessageCircle;
case 'tiktok':
return FaTiktok;
case 'telegram': case 'telegram':
return Send; return Send;
case 'email':
return Mail;
case 'link': case 'link':
return Link; return Link;
default: default:

View File

@ -3,7 +3,6 @@ import { ShareButton } from './ShareButton';
import { CopyLinkButton } from './CopyLinkButton'; import { CopyLinkButton } from './CopyLinkButton';
import { type SharePlatform, type ShareData, getShareUrl } from '@/lib/social-utils'; import { type SharePlatform, type ShareData, getShareUrl } from '@/lib/social-utils';
import { trackShare } from '@/lib/analytics'; import { trackShare } from '@/lib/analytics';
import { usePostHog } from '@posthog/react';
export type SocialShareVariant = 'default' | 'compact' | 'footer' | 'floating'; export type SocialShareVariant = 'default' | 'compact' | 'footer' | 'floating';
@ -14,7 +13,7 @@ interface SocialShareButtonsProps extends ShareData {
onShare?: (platform: SharePlatform) => void; onShare?: (platform: SharePlatform) => void;
} }
const PLATFORMS: SharePlatform[] = ['facebook', 'twitter', 'instagram', 'tiktok', 'telegram', 'link']; const PLATFORMS: SharePlatform[] = ['facebook', 'twitter', 'whatsapp', 'telegram', 'email', 'link'];
export function SocialShareButtons({ export function SocialShareButtons({
articleId, articleId,
@ -29,7 +28,6 @@ export function SocialShareButtons({
}: SocialShareButtonsProps) { }: SocialShareButtonsProps) {
const [isTracking, setIsTracking] = useState(false); const [isTracking, setIsTracking] = useState(false);
const [isExpanded, setIsExpanded] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const posthog = usePostHog();
const shareData: ShareData = { const shareData: ShareData = {
title, title,
@ -50,50 +48,21 @@ export function SocialShareButtons({
// Note: We don't send IP address from frontend for privacy reasons // Note: We don't send IP address from frontend for privacy reasons
// Backend should extract it from the request if needed // Backend should extract it from the request if needed
}); });
posthog.capture('article_shared', {
article_id: articleId,
platform,
article_title: title,
article_url: url,
});
// Call the onShare callback if provided // Call the onShare callback if provided
if (onShare) { if (onShare) {
onShare(platform); onShare(platform);
} }
// For Instagram and TikTok, use Web Share API if available // Open share URL in new window for social platforms
if (platform === 'instagram' || platform === 'tiktok') { if (platform !== 'link') {
if (navigator.share) {
try {
await navigator.share({
title: shareData.title,
text: shareData.excerpt,
url: shareData.url,
});
} catch (shareError) {
// User cancelled or share failed - fallback to copying link
if ((shareError as Error).name !== 'AbortError') {
const { copyToClipboard } = await import('@/lib/social-utils');
await copyToClipboard(shareData.url);
alert('Link copied! You can now paste it in ' + (platform === 'instagram' ? 'Instagram' : 'TikTok'));
}
}
} else {
// Web Share API not available - copy link as fallback
const { copyToClipboard } = await import('@/lib/social-utils');
await copyToClipboard(shareData.url);
alert('Link copied! You can now paste it in ' + (platform === 'instagram' ? 'Instagram' : 'TikTok'));
}
} else if (platform !== 'link') {
// Open share URL in new window for other social platforms
const shareUrl = getShareUrl(platform, shareData); const shareUrl = getShareUrl(platform, shareData);
window.open(shareUrl, '_blank', 'noopener,noreferrer'); window.open(shareUrl, '_blank', 'noopener,noreferrer');
} }
} catch (error) { } catch (error) {
console.error('Failed to track share:', error); console.error('Failed to track share:', error);
// Still open the share URL even if tracking fails // Still open the share URL even if tracking fails
if (platform !== 'link' && platform !== 'instagram' && platform !== 'tiktok') { if (platform !== 'link') {
const shareUrl = getShareUrl(platform, shareData); const shareUrl = getShareUrl(platform, shareData);
window.open(shareUrl, '_blank', 'noopener,noreferrer'); window.open(shareUrl, '_blank', 'noopener,noreferrer');
} }

View File

@ -83,7 +83,7 @@ export function HeroArticle() {
<span> <span>
{new Date(article.createdAt).toLocaleDateString('mk-MK', { {new Date(article.createdAt).toLocaleDateString('mk-MK', {
day: 'numeric', day: 'numeric',
month: 'long', month: 'short',
year: 'numeric', year: 'numeric',
})} })}
</span> </span>
@ -98,7 +98,7 @@ export function HeroArticle() {
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Eye className="w-4 h-4" /> <Eye className="w-4 h-4" />
<span>{article.views || 0} прегледи</span> <span>{article.views} views</span>
</div> </div>
</div> </div>
@ -122,9 +122,9 @@ export function HeroArticle() {
)} )}
<div className="flex items-center justify-between pt-4 border-t-2 border-foreground/10"> <div className="flex items-center justify-between pt-4 border-t-2 border-foreground/10">
<Link to="/articles/$id" params={{ id: article.id }}> <Link to={`/articles/${article.id}`}>
<Button variant="brutalAccent" className="gap-2"> <Button variant="brutalAccent" className="gap-2">
Прочитај повеќе Read Full Story
<ArrowRight className="w-4 h-4" /> <ArrowRight className="w-4 h-4" />
</Button> </Button>
</Link> </Link>
@ -132,7 +132,7 @@ export function HeroArticle() {
<div className="font-body text-xs uppercase tracking-wider text-muted-foreground"> <div className="font-body text-xs uppercase tracking-wider text-muted-foreground">
<span className="font-bold text-foreground"> <span className="font-bold text-foreground">
{(article.facebookShares || 0) + (article.twitterShares || 0) + (article.whatsappShares || 0) + (article.telegramShares || 0)} {(article.facebookShares || 0) + (article.twitterShares || 0) + (article.whatsappShares || 0) + (article.telegramShares || 0)}
</span> споделувања </span> shares
</div> </div>
</div> </div>
</div> </div>

View File

@ -65,8 +65,7 @@ export function LatestArticlesGrid() {
className={`group border-brutal-sm bg-card hover:shadow-brutal transition-all duration-150 hover:-translate-y-1 animate-fade-in-up stagger-${Math.min(index + 1, 12)}`} className={`group border-brutal-sm bg-card hover:shadow-brutal transition-all duration-150 hover:-translate-y-1 animate-fade-in-up stagger-${Math.min(index + 1, 12)}`}
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block" className="block"
> >
{article.featuredImage ? ( {article.featuredImage ? (
@ -108,12 +107,12 @@ export function LatestArticlesGrid() {
</span> </span>
{article.category && ( {article.category && (
<a <Link
href={`/${article.category.slug}`} to={`/${article.category.slug}`}
className="px-2 py-0.5 border border-foreground bg-background text-foreground text-[10px] hover:bg-accent hover:border-accent transition-colors" className="px-2 py-0.5 border border-foreground bg-background text-foreground text-[10px] hover:bg-accent hover:border-accent transition-colors"
> >
{article.category.name} {article.category.name}
</a> </Link>
)} )}
</div> </div>
@ -122,7 +121,7 @@ export function LatestArticlesGrid() {
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -2,12 +2,9 @@ import { useQuery } from '@tanstack/react-query';
import { Link } from '@tanstack/react-router'; import { Link } from '@tanstack/react-router';
import { fetchPinnedLiveBlogs } from '@/lib/api'; import { fetchPinnedLiveBlogs } from '@/lib/api';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Calendar, Eye, MessageSquare, Pin, ChevronDown, ChevronUp, Clock } from 'lucide-react'; import { Calendar, Eye, MessageSquare, Pin } from 'lucide-react';
import { useState } from 'react';
export function PinnedLiveBlogsSidebar() { export function PinnedLiveBlogsSidebar() {
const [showUpdates, setShowUpdates] = useState(true);
const { data: liveBlogs, isLoading, error } = useQuery({ const { data: liveBlogs, isLoading, error } = useQuery({
queryKey: ['pinned-live-blogs'], queryKey: ['pinned-live-blogs'],
queryFn: fetchPinnedLiveBlogs, queryFn: fetchPinnedLiveBlogs,
@ -50,52 +47,6 @@ export function PinnedLiveBlogsSidebar() {
}); });
}; };
const formatRelativeTime = (dateString: string) => {
const date = new Date(dateString);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMins = Math.floor(diffMs / 60000);
const diffHours = Math.floor(diffMs / 3600000);
const diffDays = Math.floor(diffMs / 86400000);
if (diffMins < 1) return 'сега';
if (diffMins < 60) return `${diffMins}м`;
if (diffHours < 24) return `${diffHours}ч`;
return `${diffDays}д`;
};
// Collect last 5 updates from all pinned live blogs
const getLastFiveUpdates = () => {
if (!liveBlogs) return [];
const allUpdates: Array<{
id: string;
content: string;
createdAt: string;
liveBlogTitle: string;
liveBlogSlug: string;
}> = [];
liveBlogs.forEach((liveBlog) => {
if (liveBlog.updates && liveBlog.updates.length > 0) {
liveBlog.updates.forEach((update) => {
allUpdates.push({
...update,
liveBlogTitle: liveBlog.title,
liveBlogSlug: liveBlog.slug,
});
});
}
});
// Sort by date descending and take first 5
return allUpdates
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
.slice(0, 5);
};
const lastFiveUpdates = getLastFiveUpdates();
if (isLoading) { if (isLoading) {
return ( return (
<div className="border-brutal-sm bg-card p-6"> <div className="border-brutal-sm bg-card p-6">
@ -151,63 +102,10 @@ export function PinnedLiveBlogsSidebar() {
return ( return (
<div className="border-brutal-sm bg-card p-6"> <div className="border-brutal-sm bg-card p-6">
{/* Latest Updates Section - Collapsible */}
{lastFiveUpdates.length > 0 && (
<div className="mb-6 pb-6 border-b-2 border-foreground/10">
<button
onClick={() => setShowUpdates(!showUpdates)}
className="w-full flex items-center justify-between mb-4 group"
>
<div className="flex items-center gap-2">
<Clock className="h-5 w-5 text-accent" />
<h3 className="text-xl font-display">Свежо набрано</h3>
</div>
<div className="flex items-center gap-2">
<span className="px-2 py-1 border-2 border-foreground bg-foreground text-background text-xs font-body font-bold uppercase">
{lastFiveUpdates.length}
</span>
{showUpdates ? (
<ChevronUp className="h-4 w-4 transition-transform" />
) : (
<ChevronDown className="h-4 w-4 transition-transform" />
)}
</div>
</button>
{showUpdates && (
<div className="space-y-3 animate-scale-in">
{lastFiveUpdates.map((update) => (
<Link
key={update.id}
to="/live-blogs/$slug"
params={{ slug: update.liveBlogSlug }}
className="block group"
>
<div className="p-3 border-2 border-foreground/10 hover:border-accent hover:bg-accent/5 transition-all duration-150">
<div className="flex items-start justify-between gap-2 mb-2">
<span className="text-xs font-body font-bold text-muted-foreground line-clamp-1">
{update.liveBlogTitle}
</span>
<span className="text-xs font-body text-muted-foreground whitespace-nowrap">
{formatRelativeTime(update.createdAt)}
</span>
</div>
<p className="text-sm font-body text-foreground line-clamp-2 group-hover:text-accent transition-colors">
{update.content.replace(/<[^>]*>/g, '').substring(0, 120)}
{update.content.length > 120 ? '...' : ''}
</p>
</div>
</Link>
))}
</div>
)}
</div>
)}
<div className="flex items-center justify-between mb-6 pb-4 border-b-2 border-foreground/10"> <div className="flex items-center justify-between mb-6 pb-4 border-b-2 border-foreground/10">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Pin className="h-5 w-5 text-accent" /> <Pin className="h-5 w-5 text-accent" />
<h3 className="text-xl font-display">Во Живо</h3> <h3 className="text-xl font-display">Pinned Live</h3>
</div> </div>
<span className="px-2 py-1 border-2 border-foreground bg-foreground text-background text-xs font-body font-bold uppercase"> <span className="px-2 py-1 border-2 border-foreground bg-foreground text-background text-xs font-body font-bold uppercase">
{liveBlogs.length} {liveBlogs.length}
@ -280,7 +178,7 @@ export function PinnedLiveBlogsSidebar() {
<div className="mt-6 pt-4 border-t-2 border-foreground/10"> <div className="mt-6 pt-4 border-t-2 border-foreground/10">
<Link to="/live-blogs" className="block"> <Link to="/live-blogs" className="block">
<Button variant="brutal" className="w-full justify-center"> <Button variant="brutal" className="w-full justify-center">
... Сите Live
</Button> </Button>
</Link> </Link>
</div> </div>

View File

@ -32,7 +32,6 @@ export function Header() {
{ to: '/science', label: 'Наука' }, { to: '/science', label: 'Наука' },
{ to: '/archive', label: 'Архива' }, { to: '/archive', label: 'Архива' },
{ to: '/live-blogs', label: 'LIVE' }, { to: '/live-blogs', label: 'LIVE' },
{ to: '/about', label: 'Упатство за употреба' },
]; ];
const adminLinks = [ const adminLinks = [
@ -59,7 +58,7 @@ export function Header() {
<div className="container mx-auto max-w-6xl px-4 py-4"> <div className="container mx-auto max-w-6xl px-4 py-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<Link to="/" className="group"> <Link to="/" className="group">
<h1 className="text-4xl md:text-5xl font-display tracking-tight whitespace-nowrap"> <h1 className="text-4xl md:text-5xl font-display tracking-tight">
<span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-1">P</span> <span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-1">P</span>
<span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-0.5 delay-75">l</span> <span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-0.5 delay-75">l</span>
<span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-0 delay-100">a</span> <span className="inline-block transition-transform group-hover:-translate-y-1 group-hover:translate-x-0 delay-100">a</span>

View File

@ -1,120 +0,0 @@
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { AlertTriangle, Laugh, Coffee } from 'lucide-react';
export function AboutComponent() {
return (
<div className="py-8 max-w-4xl mx-auto">
<div className="mb-12 text-center">
<h1 className="text-4xl md:text-6xl font-display mb-4">
Упатство за употреба
</h1>
<p className="text-xl text-muted-foreground font-body">
Сè што треба да знаете за Placebo.mk
</p>
</div>
<div className="space-y-6">
<Card className="border-brutal-sm">
<CardHeader>
<div className="flex items-center gap-3">
<AlertTriangle className="w-8 h-8 text-accent" />
<CardTitle className="text-2xl font-display">Предупредување</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-6 font-body p-3">
{/* <p className="text-lg"> */}
{/* <strong>Placebo.mk</strong> е сатиричен портал за вести. Сè што читате овде е измислено, преувеличено или целосно извадено од контекст. */}
{/* </p> */}
<p>
Ако веќе се налутивте, не се грижете - тоа ни беше целта. Ако сте се насмеале, уште подобро!
</p>
</CardContent>
</Card>
<Card className="border-brutal-sm">
<CardHeader>
<div className="flex items-center gap-3">
<Laugh className="w-8 h-8 text-accent" />
<CardTitle className="text-2xl font-display">Што е Placebo.mk?</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-6 font-body p-3">
<p>
Placebo.mk е портал кој ja преработува реалноста и ја претвора во апсурд. Македонските а богами и глобалните политика, култура и спорт се сервираат со добра доза сарказам и црн хумор.
</p>
{/* <p> */}
{/* Нашата мисија е едноставна: да ве насмееме, да ве натераме да размислите и да ве потсетиме дека понекогаш вистината е толку apsурдна што единствено може да се коментира со хумор. */}
{/* </p> */}
</CardContent>
</Card>
<Card className="border-brutal-sm">
<CardHeader>
<CardTitle className="text-2xl font-display">Правила за читање</CardTitle>
</CardHeader>
<CardContent className="font-body">
<ol className="list-decimal list-inside space-y-3 p-3">
<li>Не земајте ништо [од ова] во животот премногу сериозно (освен кафето што ќе ни го купите).</li>
<li>Ако не ви е смешно тогаш е трагично. Ако не ви се допаѓаме. Најдете друга страна.</li>
<li>Смеата е најдобар лек. Користете ја дневно.</li>
<li>Ако ви се допаѓа, споделете. Ако не ви се допаѓа, сепак споделете. Гледаме статистики.</li>
</ol>
</CardContent>
</Card>
<Card className="border-brutal-sm">
<CardHeader>
<CardTitle className="text-2xl font-display">Категории</CardTitle>
</CardHeader>
<CardContent className="font-body">
<ul className="space-y-3 p-3">
<li>
<strong>Општо:</strong> Општи вести и теми кои не паѓаат во другите категории
</li>
<li>
<strong>Спорт:</strong> Спортски новости, победи, порази и сè помеѓу (најчесто порази)
</li>
<li>
<strong>Уметност:</strong> Култура, музика, филм и претставување дека разбираме од уметност
</li>
<li>
<strong>Наука:</strong> Научни откритија објаснети на начин што ќе разбере и вашата баба
</li>
<li>
<strong>LIVE Блогови:</strong> Покривање во реално време на настани што го заслужуваат нашето внимание
</li>
</ul>
</CardContent>
</Card>
<Card className="border-brutal-sm bg-accent/5">
<CardHeader>
<div className="flex items-center gap-3">
<Coffee className="w-8 h-8 text-accent" />
<CardTitle className="text-2xl font-display">Поддржете не</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-4 font-body">
<p>
Сатирата не се пишува сама (иако понекогаш реалноста е поапсурдна од фикцијата).
Ако ви се допаѓа она што го правиме, размислете да ни купите кафе. Или две. Или три.
</p>
<p className="text-sm text-muted-foreground">
* Сите донации одат за кафе, инспирација и плаќање на серверите. Не нудиме фискални сметки.
</p>
</CardContent>
</Card>
<div className="mt-12 p-8 border-4 border-foreground bg-foreground text-background text-center">
<p className="text-2xl font-display mb-4">
Запомнете:
</p>
<p className="text-lg font-body">
Ако не можете да разликувате сатира од вистина,<br />
проблемот не е во нас. Проблемот е во реалноста.
</p>
</div>
</div>
</div>
);
}

View File

@ -28,8 +28,8 @@ export function ArchiveComponent() {
return ( return (
<div> <div>
<div className="mb-8"> <div className="mb-8">
<h1 className="text-3xl font-bold">Архива</h1> <h1 className="text-3xl font-bold">Articles</h1>
<p className="text-muted-foreground">Најнови вести и статии</p> <p className="text-muted-foreground">Latest news and articles</p>
</div> </div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
@ -39,8 +39,7 @@ export function ArchiveComponent() {
className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow" className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow"
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block mb-4" className="block mb-4"
> >
<h2 className="text-xl font-semibold mb-2 line-clamp-2"> <h2 className="text-xl font-semibold mb-2 line-clamp-2">
@ -58,19 +57,19 @@ export function ArchiveComponent() {
<span> <span>
{new Date(article.createdAt).toLocaleDateString('mk-MK', { {new Date(article.createdAt).toLocaleDateString('mk-MK', {
day: 'numeric', day: 'numeric',
month: 'long', month: 'short',
year: 'numeric', year: 'numeric',
})} })}
</span> </span>
<span></span> <span></span>
<span>{article.views || 0} прегледи</span> <span>{article.views} views</span>
</div> </div>
<SocialShareButtons <SocialShareButtons
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -42,14 +42,14 @@ export function ArticleDetailComponent({ id }: { id: string }) {
return ( return (
<article className="max-w-3xl mx-auto"> <article className="max-w-3xl mx-auto">
<Link <Link
to="/archive" to="/articles"
className="inline-flex items-center gap-2 text-muted-foreground hover:text-foreground mb-8" className="inline-flex items-center gap-2 text-muted-foreground hover:text-foreground mb-8"
> >
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="m15 18-6-6 6-6" /> <path d="m15 18-6-6 6-6" />
<path d="M19 6H5" /> <path d="M19 6H5" />
</svg> </svg>
Назад кон вести Back to articles
</Link> </Link>
<h1 className="text-4xl font-bold mb-6">{data.title}</h1> <h1 className="text-4xl font-bold mb-6">{data.title}</h1>
@ -63,11 +63,11 @@ export function ArticleDetailComponent({ id }: { id: string }) {
})} })}
</span> </span>
<span></span> <span></span>
<span>{data.views || 0} прегледи</span> <span>{data.views} views</span>
{data.author && ( {data.author && (
<> <>
<span></span> <span></span>
<span>Од {data.author.name}</span> <span>By {data.author.name}</span>
</> </>
)} )}
</div> </div>
@ -78,7 +78,7 @@ export function ArticleDetailComponent({ id }: { id: string }) {
articleId={data.id} articleId={data.id}
title={data.title} title={data.title}
url={typeof window !== 'undefined' ? window.location.href : ''} url={typeof window !== 'undefined' ? window.location.href : ''}
excerpt={data.excerpt ?? undefined} excerpt={data.excerpt}
image={data.featuredImage} image={data.featuredImage}
tags={data.tags} tags={data.tags}
/> />
@ -151,14 +151,10 @@ export function ArticleDetailComponent({ id }: { id: string }) {
)} )}
<div className="prose prose-slate max-w-none"> <div className="prose prose-slate max-w-none">
<div className="text-lg leading-relaxed mb-6 text-justify"> <div className="text-lg leading-relaxed mb-6">
<ReactMarkdown <ReactMarkdown
remarkPlugins={[remarkGfm]} remarkPlugins={[remarkGfm]}
components={{ components={{
p: (props) => <p {...props} className="mb-4 text-justify" />,
ul: (props) => <ul {...props} className="list-disc list-outside ml-6 mb-4 space-y-2" />,
ol: (props) => <ol {...props} className="list-decimal list-outside ml-6 mb-4 space-y-2" />,
li: (props) => <li {...props} className="text-justify" />,
img: (props) => ( img: (props) => (
<img <img
{...props} {...props}
@ -202,7 +198,7 @@ export function ArticleDetailComponent({ id }: { id: string }) {
articleId={data.id} articleId={data.id}
title={data.title} title={data.title}
url={typeof window !== 'undefined' ? window.location.href : ''} url={typeof window !== 'undefined' ? window.location.href : ''}
excerpt={data.excerpt ?? undefined} excerpt={data.excerpt}
image={data.featuredImage} image={data.featuredImage}
tags={data.tags} tags={data.tags}
variant="footer" variant="footer"

View File

@ -57,7 +57,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
{/* Hero Article - 2/3 width */} {/* Hero Article - 2/3 width */}
<div className="lg:col-span-2"> <div className="lg:col-span-2">
<div className="rounded-xl border bg-card overflow-hidden group hover:shadow-lg transition-shadow"> <div className="rounded-xl border bg-card overflow-hidden group hover:shadow-lg transition-shadow">
<Link to="/articles/$id" params={{ id: heroArticle.id }} className="block"> <Link to={`/articles/${heroArticle.id}`} className="block">
{heroArticle.featuredImage ? ( {heroArticle.featuredImage ? (
<div className="relative h-64 md:h-80 overflow-hidden"> <div className="relative h-64 md:h-80 overflow-hidden">
<img <img
@ -80,7 +80,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
</Link> </Link>
<div className="p-6"> <div className="p-6">
<Link to="/articles/$id" params={{ id: heroArticle.id }} className="block"> <Link to={`/articles/${heroArticle.id}`} className="block">
<h2 className="text-2xl font-bold mb-3 group-hover:text-primary transition-colors"> <h2 className="text-2xl font-bold mb-3 group-hover:text-primary transition-colors">
{heroArticle.title} {heroArticle.title}
</h2> </h2>
@ -108,7 +108,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
articleId={heroArticle.id} articleId={heroArticle.id}
title={heroArticle.title} title={heroArticle.title}
url={`${window.location.origin}/articles/${heroArticle.id}`} url={`${window.location.origin}/articles/${heroArticle.id}`}
excerpt={heroArticle.excerpt ?? undefined} excerpt={heroArticle.excerpt}
image={heroArticle.featuredImage} image={heroArticle.featuredImage}
tags={heroArticle.tags} tags={heroArticle.tags}
variant="compact" variant="compact"
@ -135,8 +135,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow group" className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow group"
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block mb-4" className="block mb-4"
> >
<h2 className="text-xl font-semibold mb-2 line-clamp-2 group-hover:text-primary transition-colors"> <h2 className="text-xl font-semibold mb-2 line-clamp-2 group-hover:text-primary transition-colors">
@ -166,7 +165,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -63,13 +63,13 @@ export function LiveBlogsComponent() {
<div className="flex items-center justify-between text-sm text-muted-foreground"> <div className="flex items-center justify-between text-sm text-muted-foreground">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<span>{liveBlog.viewCount || 0} прегледи</span> <span>{liveBlog.viewCount} views</span>
<span>{liveBlog.updates?.length || 0} ажурирања</span> <span>{liveBlog.updates?.length || 0} updates</span>
</div> </div>
<span> <span>
{new Date(liveBlog.createdAt).toLocaleDateString('mk-MK', { {new Date(liveBlog.createdAt).toLocaleDateString('mk-MK', {
day: 'numeric', day: 'numeric',
month: 'long', month: 'short',
year: 'numeric', year: 'numeric',
})} })}
</span> </span>

View File

@ -3,7 +3,6 @@ import { createContext, useContext, useState, useEffect } from 'react';
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import * as api from '../lib/api'; import * as api from '../lib/api';
import type { User } from '@/types'; import type { User } from '@/types';
import { usePostHog } from '@posthog/react';
interface AuthContextType { interface AuthContextType {
user: User | null; user: User | null;
@ -26,7 +25,6 @@ export function AuthProvider({ children }: AuthProviderProps) {
const [user, setUser] = useState<User | null>(null); const [user, setUser] = useState<User | null>(null);
const [token, setToken] = useState<string | null>(null); const [token, setToken] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const posthog = usePostHog();
useEffect(() => { useEffect(() => {
const initializeAuth = () => { const initializeAuth = () => {
@ -58,15 +56,6 @@ export function AuthProvider({ children }: AuthProviderProps) {
setToken(response.access_token); setToken(response.access_token);
setUser(response.user); setUser(response.user);
setIsLoading(false); setIsLoading(false);
posthog.identify(response.user.id, {
username: response.user.username,
email: response.user.email,
role: response.user.role,
});
posthog.capture('user_logged_in', {
username: response.user.username,
role: response.user.role,
});
}; };
const register = async (username: string, email: string, password: string) => { const register = async (username: string, email: string, password: string) => {
@ -77,20 +66,9 @@ export function AuthProvider({ children }: AuthProviderProps) {
setToken(response.access_token); setToken(response.access_token);
setUser(response.user); setUser(response.user);
setIsLoading(false); setIsLoading(false);
posthog.identify(response.user.id, {
username: response.user.username,
email: response.user.email,
role: response.user.role,
});
posthog.capture('user_registered', {
username: response.user.username,
email: response.user.email,
});
}; };
const logout = () => { const logout = () => {
posthog.capture('user_logged_out');
posthog.reset();
localStorage.removeItem('token'); localStorage.removeItem('token');
localStorage.removeItem('user'); localStorage.removeItem('user');
setToken(null); setToken(null);

View File

@ -1,6 +1,6 @@
import { type SharePlatform } from './social-utils'; import { type SharePlatform } from './social-utils';
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1'; const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000';
export interface TrackShareParams { export interface TrackShareParams {
articleId: string; articleId: string;
@ -11,7 +11,7 @@ export interface TrackShareParams {
export const trackShare = async (params: TrackShareParams): Promise<boolean> => { export const trackShare = async (params: TrackShareParams): Promise<boolean> => {
try { try {
const response = await fetch(`${API_BASE_URL}/analytics/share`, { const response = await fetch(`${API_BASE_URL}/api/v1/analytics/share`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -34,8 +34,8 @@ export const trackShare = async (params: TrackShareParams): Promise<boolean> =>
export const getShareStats = async (articleId?: string) => { export const getShareStats = async (articleId?: string) => {
try { try {
const url = articleId const url = articleId
? `${API_BASE_URL}/analytics/shares?articleId=${articleId}` ? `${API_BASE_URL}/api/v1/analytics/shares?articleId=${articleId}`
: `${API_BASE_URL}/analytics/shares`; : `${API_BASE_URL}/api/v1/analytics/shares`;
const response = await fetch(url, { const response = await fetch(url, {
headers: { headers: {
@ -57,7 +57,7 @@ export const getShareStats = async (articleId?: string) => {
export const getTopSharedArticles = async (limit: number = 10) => { export const getTopSharedArticles = async (limit: number = 10) => {
try { try {
const response = await fetch(`${API_BASE_URL}/analytics/shares/top?limit=${limit}`, { const response = await fetch(`${API_BASE_URL}/api/v1/analytics/shares/top?limit=${limit}`, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
@ -77,7 +77,7 @@ export const getTopSharedArticles = async (limit: number = 10) => {
export const getTotalShareStats = async () => { export const getTotalShareStats = async () => {
try { try {
const response = await fetch(`${API_BASE_URL}/analytics/shares/total`, { const response = await fetch(`${API_BASE_URL}/api/v1/analytics/shares/total`, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },

View File

@ -1,8 +1,8 @@
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1'; const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1';
// Debug logging // Debug logging
// console.log('API_BASE_URL:', API_BASE_URL); console.log('API_BASE_URL:', API_BASE_URL);
// console.log('VITE_API_URL env:', import.meta.env.VITE_API_URL); console.log('VITE_API_URL env:', import.meta.env.VITE_API_URL);
// Helper function to get auth headers // Helper function to get auth headers
function getAuthHeaders(): HeadersInit { function getAuthHeaders(): HeadersInit {
@ -142,7 +142,7 @@ export interface UpdateArticleDto {
} }
export async function fetchArticles(params: FindArticlesParams = {}): Promise<ArticlesResponse> { export async function fetchArticles(params: FindArticlesParams = {}): Promise<ArticlesResponse> {
// console.log('fetchArticles called with params:', params, 'API_BASE_URL:', API_BASE_URL); console.log('fetchArticles called with params:', params, 'API_BASE_URL:', API_BASE_URL);
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
// Convert parameters to proper types for URLSearchParams // Convert parameters to proper types for URLSearchParams
@ -157,17 +157,17 @@ export async function fetchArticles(params: FindArticlesParams = {}): Promise<Ar
}); });
const url = `${API_BASE_URL}/articles?${searchParams}`; const url = `${API_BASE_URL}/articles?${searchParams}`;
// console.log('Fetching from:', url); console.log('Fetching from:', url);
const response = await authFetch(url); const response = await authFetch(url);
// console.log('Response status:', response.status, 'ok:', response.ok); console.log('Response status:', response.status, 'ok:', response.ok);
if (!response.ok) { if (!response.ok) {
throw new Error('Failed to fetch articles'); throw new Error('Failed to fetch articles');
} }
const data = await response.json(); const data = await response.json();
// console.log('Response data:', data); console.log('Response data:', data);
return data; return data;
} }

View File

@ -1,4 +1,4 @@
export type SharePlatform = 'facebook' | 'twitter' | 'instagram' | 'tiktok' | 'telegram' | 'link'; export type SharePlatform = 'facebook' | 'twitter' | 'whatsapp' | 'telegram' | 'email' | 'link';
export interface ShareData { export interface ShareData {
title: string; title: string;
@ -12,23 +12,22 @@ export const getShareUrl = (
platform: Exclude<SharePlatform, 'link'>, platform: Exclude<SharePlatform, 'link'>,
data: ShareData data: ShareData
): string => { ): string => {
const { title, url } = data; const { title, url, excerpt } = data;
const encodedUrl = encodeURIComponent(url); const encodedUrl = encodeURIComponent(url);
const encodedTitle = encodeURIComponent(title); const encodedTitle = encodeURIComponent(title);
const encodedText = encodeURIComponent(excerpt ? `${title} - ${excerpt}` : title);
switch (platform) { switch (platform) {
case 'facebook': case 'facebook':
return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`; return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`;
case 'twitter': case 'twitter':
return `https://twitter.com/intent/tweet?url=${encodedUrl}&text=${encodedTitle}`; return `https://twitter.com/intent/tweet?url=${encodedUrl}&text=${encodedTitle}`;
case 'instagram': case 'whatsapp':
// Instagram doesn't have a web share URL, will use Web Share API in component return `https://wa.me/?text=${encodedText}%20${encodedUrl}`;
return url;
case 'tiktok':
// TikTok has limited web share support, will use Web Share API in component
return url;
case 'telegram': case 'telegram':
return `https://t.me/share/url?url=${encodedUrl}&text=${encodedTitle}`; return `https://t.me/share/url?url=${encodedUrl}&text=${encodedTitle}`;
case 'email':
return `mailto:?subject=${encodedTitle}&body=${encodedUrl}`;
default: default:
return url; return url;
} }
@ -65,12 +64,12 @@ export const getPlatformIcon = (platform: SharePlatform): string => {
return 'Facebook'; return 'Facebook';
case 'twitter': case 'twitter':
return 'Twitter'; return 'Twitter';
case 'instagram': case 'whatsapp':
return 'Instagram'; return 'MessageCircle';
case 'tiktok':
return 'TikTok';
case 'telegram': case 'telegram':
return 'Send'; return 'Send';
case 'email':
return 'Mail';
case 'link': case 'link':
return 'Link'; return 'Link';
default: default:
@ -84,12 +83,12 @@ export const getPlatformLabel = (platform: SharePlatform): string => {
return 'Facebook'; return 'Facebook';
case 'twitter': case 'twitter':
return 'Twitter'; return 'Twitter';
case 'instagram': case 'whatsapp':
return 'Instagram'; return 'WhatsApp';
case 'tiktok':
return 'TikTok';
case 'telegram': case 'telegram':
return 'Telegram'; return 'Telegram';
case 'email':
return 'Email';
case 'link': case 'link':
return 'Copy Link'; return 'Copy Link';
default: default:

View File

@ -2,7 +2,6 @@ import { StrictMode } from 'react'
import ReactDOM from 'react-dom/client' import ReactDOM from 'react-dom/client'
import { RouterProvider } from '@tanstack/react-router' import { RouterProvider } from '@tanstack/react-router'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PostHogProvider } from '@posthog/react'
import { router } from './routes' import { router } from './routes'
import { AuthProvider } from './contexts/AuthContext' import { AuthProvider } from './contexts/AuthContext'
import { initializeTheme } from './lib/theme' import { initializeTheme } from './lib/theme'
@ -12,30 +11,12 @@ initializeTheme();
const queryClient = new QueryClient() const queryClient = new QueryClient()
const posthogOptions = {
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
defaults: '2026-01-30',
} as const
// Debug PostHog configuration (dev only)
if (import.meta.env.DEV) {
console.log('PostHog Config:', {
apiKey: import.meta.env.VITE_PUBLIC_POSTHOG_KEY ? '✓ Set' : '✗ Missing',
apiHost: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
})
}
ReactDOM.createRoot(document.getElementById('root')!).render( ReactDOM.createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<PostHogProvider
apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY}
options={posthogOptions}
>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<AuthProvider> <AuthProvider>
<RouterProvider router={router} /> <RouterProvider router={router} />
</AuthProvider> </AuthProvider>
</QueryClientProvider> </QueryClientProvider>
</PostHogProvider>
</StrictMode>, </StrictMode>,
) )

View File

@ -11,7 +11,6 @@ import { AuthPage } from './components/routes/AuthPage'
import { SportComponent } from './components/routes/SportComponent' import { SportComponent } from './components/routes/SportComponent'
import { ArtComponent } from './components/routes/ArtComponent' import { ArtComponent } from './components/routes/ArtComponent'
import { ScienceComponent } from './components/routes/ScienceComponent' import { ScienceComponent } from './components/routes/ScienceComponent'
import { AboutComponent } from './components/routes/AboutComponent'
import { ProtectedRoute } from './components/auth/ProtectedRoute' import { ProtectedRoute } from './components/auth/ProtectedRoute'
import { Header } from './components/layout/Header' import { Header } from './components/layout/Header'
import { HeroArticle } from './components/home/HeroArticle' import { HeroArticle } from './components/home/HeroArticle'
@ -45,7 +44,7 @@ const rootRoute = createRootRoute({
<div> <div>
<h3 className="font-display text-3xl mb-4">Placebo.mk</h3> <h3 className="font-display text-3xl mb-4">Placebo.mk</h3>
<p className="font-body text-sm text-background/70"> <p className="font-body text-sm text-background/70">
Сатрирични вести и коментари за локални и глобални настани. Непристојни сатрирични вести и коментари за локални и глобални настани во Македонија.
</p> </p>
</div> </div>
<div> <div>
@ -73,7 +72,7 @@ const rootRoute = createRootRoute({
</div> </div>
</div> </div>
<div className="mt-12 pt-8 border-t border-background/20 text-center font-body text-xs uppercase tracking-wider"> <div className="mt-12 pt-8 border-t border-background/20 text-center font-body text-xs uppercase tracking-wider">
© 2026 Placebo.mk Сите права се заштитени. Или не се. © 2025 Placebo.mk Сите права се заштитени. Или не се.
</div> </div>
</div> </div>
</footer> </footer>
@ -103,7 +102,7 @@ const indexRoute = createRoute({
<div className="text-center"> <div className="text-center">
<h2 className="text-4xl md:text-6xl font-display mb-4">Placebo.mk</h2> <h2 className="text-4xl md:text-6xl font-display mb-4">Placebo.mk</h2>
<p className="font-body text-lg max-w-2xl mx-auto text-background/80 mb-8"> <p className="font-body text-lg max-w-2xl mx-auto text-background/80 mb-8">
Сатрирични вести и коментари за локални и глобални настани. Непристојно сатрирични вести и коментари за локални и глобални настани во Македонија.
Затоа што понекогаш вистината боли повеќе од фикцијата. Затоа што понекогаш вистината боли повеќе од фикцијата.
</p> </p>
<div className="flex flex-col sm:flex-row gap-4 justify-center"> <div className="flex flex-col sm:flex-row gap-4 justify-center">
@ -139,7 +138,7 @@ const indexRoute = createRoute({
</div> </div>
<h3 className="text-2xl font-display mb-2">Без филтер</h3> <h3 className="text-2xl font-display mb-2">Без филтер</h3>
<p className="font-body text-sm text-muted-foreground"> <p className="font-body text-sm text-muted-foreground">
Не разликуване нијанси. Не користиме дипломатски јазик. Само искрени коментари. Не правиме нијанси. Не правиме дипломатски јазик. Само искрени (и малку лоши) коментари.
</p> </p>
</div> </div>
@ -149,7 +148,7 @@ const indexRoute = createRoute({
</div> </div>
<h3 className="text-2xl font-display mb-2">Live Покривање</h3> <h3 className="text-2xl font-display mb-2">Live Покривање</h3>
<p className="font-body text-sm text-muted-foreground"> <p className="font-body text-sm text-muted-foreground">
Ажурирања во реално време, прекршени вести. Нема одложувања, само факти. Ажурирања во реално време за разбивачки вести со нашиот систем за live blogging. Нема одложувања, само факти.
</p> </p>
</div> </div>
</div> </div>
@ -182,12 +181,6 @@ const scienceRoute = createRoute({
component: ScienceComponent, component: ScienceComponent,
}) })
const aboutRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/about',
component: AboutComponent,
})
const articleDetailRoute = createRoute({ const articleDetailRoute = createRoute({
getParentRoute: () => rootRoute, getParentRoute: () => rootRoute,
path: '/articles/$id', path: '/articles/$id',
@ -196,7 +189,7 @@ const articleDetailRoute = createRoute({
return <ArticleDetailComponent id={id} /> return <ArticleDetailComponent id={id} />
}, },
loader: async ({ params }) => { loader: async ({ params }) => {
const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1'}/articles/${params.id}`) const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3000'}/api/v1/articles/${params.id}`)
if (!response.ok) { if (!response.ok) {
return { article: null } return { article: null }
} }
@ -315,7 +308,6 @@ const routeTree = rootRoute.addChildren([
sportRoute, sportRoute,
artRoute, artRoute,
scienceRoute, scienceRoute,
aboutRoute,
articleDetailRoute, articleDetailRoute,
liveBlogsRoute, liveBlogsRoute,
liveBlogDetailRoute, liveBlogDetailRoute,

View File

@ -1,5 +1,7 @@
@import "tailwindcss"; @import "tailwindcss";
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');
@theme { @theme {
--color-primary: oklch(0.08 0 0); --color-primary: oklch(0.08 0 0);
--color-primary-foreground: oklch(0.98 0 0); --color-primary-foreground: oklch(0.98 0 0);
@ -74,19 +76,10 @@
--shadow-brutal-accent: 4px 4px 0px 0px hsl(193 48% 67%); --shadow-brutal-accent: 4px 4px 0px 0px hsl(193 48% 67%);
} }
@layer base {
* { * {
border-color: hsl(var(--border));
box-sizing: border-box; box-sizing: border-box;
} }
h1, h2, h3, h4, h5, h6 {
font-family: var(--font-display);
letter-spacing: 0.02em;
text-transform: uppercase;
}
}
html { html {
scroll-behavior: smooth; scroll-behavior: smooth;
} }
@ -332,6 +325,18 @@ body::before {
overflow: hidden; overflow: hidden;
} }
@layer base {
* {
border-color: hsl(var(--border));
}
h1, h2, h3, h4, h5, h6 {
font-family: var(--font-display);
letter-spacing: 0.02em;
text-transform: uppercase;
}
}
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 12px; width: 12px;
} }

View File

@ -1,13 +1,10 @@
import { defineConfig, loadEnv } from 'vite' import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite' import tailwindcss from '@tailwindcss/vite'
import path from 'path' import path from 'path'
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig(({ mode }) => { export default defineConfig({
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [ plugins: [
react(), react(),
tailwindcss(), tailwindcss(),
@ -27,13 +24,5 @@ export default defineConfig(({ mode }) => {
host: true, // Listen on all addresses host: true, // Listen on all addresses
port: 5173, port: 5173,
strictPort: true, strictPort: true,
proxy: {
'/ingest': {
target: env.VITE_PUBLIC_POSTHOG_HOST || 'https://eu.i.posthog.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/ingest/, ''),
}, },
},
},
}
}) })

1632
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,3 @@ VITE_API_URL=http://localhost:3000/api/v1
# ===== COMMON ===== # ===== COMMON =====
VITE_CMS_URL=http://localhost:1337 VITE_CMS_URL=http://localhost:1337
# ===== POSTHOG ANALYTICS =====
VITE_PUBLIC_POSTHOG_KEY=phc_kuDGT1kUmJmijLRjiQaKWIaU4JBdFW0aELW2hIGlBXR
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com

View File

@ -1,27 +1,16 @@
# PWA Dockerfile for Placebo.mk Progressive Web App # Frontend Dockerfile for Placebo.mk TanStack React App
# Build stage # Build stage
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Build arguments for environment variables
ARG VITE_API_URL
ARG VITE_CMS_URL
ARG VITE_PUBLIC_POSTHOG_KEY
ARG VITE_PUBLIC_POSTHOG_HOST
# Set environment variables for build
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_CMS_URL=$VITE_CMS_URL
ENV VITE_PUBLIC_POSTHOG_KEY=$VITE_PUBLIC_POSTHOG_KEY
ENV VITE_PUBLIC_POSTHOG_HOST=$VITE_PUBLIC_POSTHOG_HOST
# Copy package files # Copy package files
COPY package.json package-lock.json* ./ COPY package*.json ./
COPY package-lock.json* ./
# Install dependencies # Install dependencies
RUN npm install --legacy-peer-deps RUN npm ci
# Copy source code # Copy source code
COPY . . COPY . .
@ -32,12 +21,19 @@ RUN npm run build
# Production stage # Production stage
FROM nginx:alpine FROM nginx:alpine
# Create non-root user
RUN addgroup -g 1001 -S nginx && \
adduser -S nginx -u 1001 -G nginx
# Copy built application from builder stage # Copy built application from builder stage
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html
# Copy nginx configuration # Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
# Switch to non-root user
USER nginx
# Health check # Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1

View File

@ -6,7 +6,7 @@ import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config' import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([ export default defineConfig([
globalIgnores(['dist', 'dev-dist']), globalIgnores(['dist']),
{ {
files: ['**/*.{ts,tsx}'], files: ['**/*.{ts,tsx}'],
extends: [ extends: [

View File

@ -5,16 +5,12 @@
<link rel="icon" type="image/svg+xml" href="/icons/favicon-32.svg" /> <link rel="icon" type="image/svg+xml" href="/icons/favicon-32.svg" />
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.svg" /> <link rel="apple-touch-icon" href="/icons/apple-touch-icon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://eu-assets.i.posthog.com; style-src 'self' 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: https:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.placebo.mk https://cms.placebo.mk https://app.placebo.mk wss://api.placebo.mk https://eu.i.posthog.com https://eu-assets.i.posthog.com; manifest-src 'self';">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta name="description" content="Сатирични вести од Македонија - Placebo.mk" /> <meta name="description" content="Сатирични вести од Македонија - Placebo.mk" />
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Placebo" /> <meta name="apple-mobile-web-app-title" content="Placebo" />
<title>Placebo.mk - Сатирични вести од Македонија</title> <title>Placebo.mk</title>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

View File

@ -46,7 +46,7 @@ http {
index index.html; index index.html;
# Security headers for frontend # Security headers for frontend
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://eu-assets.i.posthog.com; style-src 'self' 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: https:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.placebo.mk https://cms.placebo.mk https://app.placebo.mk wss://api.placebo.mk https://eu.i.posthog.com https://eu-assets.i.posthog.com; manifest-src 'self';" always; add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' http://localhost:3000 http://localhost:1337;" always;
# Handle React Router # Handle React Router
location / { location / {
@ -60,35 +60,35 @@ http {
add_header Cache-Control "public, immutable"; add_header Cache-Control "public, immutable";
} }
# API proxy (for local dev only - in prod use public URL) # API proxy
# location /api/ { location /api/ {
# proxy_pass http://backend:3000/; proxy_pass http://backend:3000/;
# proxy_http_version 1.1; proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host; proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# proxy_read_timeout 300; proxy_read_timeout 300;
# proxy_connect_timeout 300; proxy_connect_timeout 300;
# } }
# CMS proxy (for local dev only - in prod use public URL) # CMS proxy
# location /cms/ { location /cms/ {
# proxy_pass http://cms:1337/; proxy_pass http://cms:1337/;
# proxy_http_version 1.1; proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host; proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# proxy_read_timeout 300; proxy_read_timeout 300;
# proxy_connect_timeout 300; proxy_connect_timeout 300;
# } }
# Health check endpoint # Health check endpoint
location /health { location /health {

473
pwa/package-lock.json generated
View File

@ -8,7 +8,6 @@
"name": "pwa", "name": "pwa",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"@posthog/react": "^1.8.1",
"@radix-ui/react-label": "^2.1.8", "@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-select": "^2.2.6", "@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-slot": "^1.2.4", "@radix-ui/react-slot": "^1.2.4",
@ -18,10 +17,8 @@
"@tanstack/react-query": "^5.90.14", "@tanstack/react-query": "^5.90.14",
"@tanstack/react-router": "^1.144.0", "@tanstack/react-router": "^1.144.0",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"posthog-js": "^1.356.1",
"react": "^19.2.0", "react": "^19.2.0",
"react-dom": "^19.2.4", "react-dom": "^19.2.0",
"react-icons": "^5.6.0",
"react-markdown": "^10.1.0", "react-markdown": "^10.1.0",
"remark-gfm": "^4.0.1", "remark-gfm": "^4.0.1",
"vite-plugin-pwa": "^1.2.0", "vite-plugin-pwa": "^1.2.0",
@ -2247,348 +2244,6 @@
"@jridgewell/sourcemap-codec": "^1.4.14" "@jridgewell/sourcemap-codec": "^1.4.14"
} }
}, },
"node_modules/@opentelemetry/api": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz",
"integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==",
"license": "Apache-2.0",
"peer": true,
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/@opentelemetry/api-logs": {
"version": "0.208.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.208.0.tgz",
"integrity": "sha512-CjruKY9V6NMssL/T1kAFgzosF1v9o6oeN+aX5JB/C/xPNtmgIJqcXHG7fA82Ou1zCpWGl4lROQUKwUNE1pMCyg==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.3.0"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/@opentelemetry/core": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-2.2.0.tgz",
"integrity": "sha512-FuabnnUm8LflnieVxs6eP7Z383hgQU4W1e3KJS6aOG3RxWxcHyBxH8fDMHNgu/gFx/M2jvTOW/4/PHhLz6bjWw==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.0.0 <1.10.0"
}
},
"node_modules/@opentelemetry/exporter-logs-otlp-http": {
"version": "0.208.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/exporter-logs-otlp-http/-/exporter-logs-otlp-http-0.208.0.tgz",
"integrity": "sha512-jOv40Bs9jy9bZVLo/i8FwUiuCvbjWDI+ZW13wimJm4LjnlwJxGgB+N/VWOZUTpM+ah/awXeQqKdNlpLf2EjvYg==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api-logs": "0.208.0",
"@opentelemetry/core": "2.2.0",
"@opentelemetry/otlp-exporter-base": "0.208.0",
"@opentelemetry/otlp-transformer": "0.208.0",
"@opentelemetry/sdk-logs": "0.208.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": "^1.3.0"
}
},
"node_modules/@opentelemetry/otlp-exporter-base": {
"version": "0.208.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.208.0.tgz",
"integrity": "sha512-gMd39gIfVb2OgxldxUtOwGJYSH8P1kVFFlJLuut32L6KgUC4gl1dMhn+YC2mGn0bDOiQYSk/uHOdSjuKp58vvA==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/otlp-transformer": "0.208.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": "^1.3.0"
}
},
"node_modules/@opentelemetry/otlp-transformer": {
"version": "0.208.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/otlp-transformer/-/otlp-transformer-0.208.0.tgz",
"integrity": "sha512-DCFPY8C6lAQHUNkzcNT9R+qYExvsk6C5Bto2pbNxgicpcSWbe2WHShLxkOxIdNcBiYPdVHv/e7vH7K6TI+C+fQ==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api-logs": "0.208.0",
"@opentelemetry/core": "2.2.0",
"@opentelemetry/resources": "2.2.0",
"@opentelemetry/sdk-logs": "0.208.0",
"@opentelemetry/sdk-metrics": "2.2.0",
"@opentelemetry/sdk-trace-base": "2.2.0",
"protobufjs": "^7.3.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": "^1.3.0"
}
},
"node_modules/@opentelemetry/otlp-transformer/node_modules/@opentelemetry/resources": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.2.0.tgz",
"integrity": "sha512-1pNQf/JazQTMA0BiO5NINUzH0cbLbbl7mntLa4aJNmCCXSj0q03T5ZXXL0zw4G55TjdL9Tz32cznGClf+8zr5A==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/resources": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.5.1.tgz",
"integrity": "sha512-BViBCdE/GuXRlp9k7nS1w6wJvY5fnFX5XvuEtWsTAOQFIO89Eru7lGW3WbfbxtCuZ/GbrJfAziXG0w0dpxL7eQ==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.5.1",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-2.5.1.tgz",
"integrity": "sha512-Dwlc+3HAZqpgTYq0MUyZABjFkcrKTePwuiFVLjahGD8cx3enqihmpAmdgNFO1R4m/sIe5afjJrA25Prqy4NXlA==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.0.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-logs": {
"version": "0.208.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-logs/-/sdk-logs-0.208.0.tgz",
"integrity": "sha512-QlAyL1jRpOeaqx7/leG1vJMp84g0xKP6gJmfELBpnI4O/9xPX+Hu5m1POk9Kl+veNkyth5t19hRlN6tNY1sjbA==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api-logs": "0.208.0",
"@opentelemetry/core": "2.2.0",
"@opentelemetry/resources": "2.2.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.4.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-logs/node_modules/@opentelemetry/resources": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.2.0.tgz",
"integrity": "sha512-1pNQf/JazQTMA0BiO5NINUzH0cbLbbl7mntLa4aJNmCCXSj0q03T5ZXXL0zw4G55TjdL9Tz32cznGClf+8zr5A==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-metrics": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-2.2.0.tgz",
"integrity": "sha512-G5KYP6+VJMZzpGipQw7Giif48h6SGQ2PFKEYCybeXJsOCB4fp8azqMAAzE5lnnHK3ZVwYQrgmFbsUJO/zOnwGw==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/resources": "2.2.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.9.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-metrics/node_modules/@opentelemetry/resources": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.2.0.tgz",
"integrity": "sha512-1pNQf/JazQTMA0BiO5NINUzH0cbLbbl7mntLa4aJNmCCXSj0q03T5ZXXL0zw4G55TjdL9Tz32cznGClf+8zr5A==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-trace-base": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-2.2.0.tgz",
"integrity": "sha512-xWQgL0Bmctsalg6PaXExmzdedSp3gyKV8mQBwK/j9VGdCDu2fmXIb2gAehBKbkXCpJ4HPkgv3QfoJWRT4dHWbw==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/resources": "2.2.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/sdk-trace-base/node_modules/@opentelemetry/resources": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-2.2.0.tgz",
"integrity": "sha512-1pNQf/JazQTMA0BiO5NINUzH0cbLbbl7mntLa4aJNmCCXSj0q03T5ZXXL0zw4G55TjdL9Tz32cznGClf+8zr5A==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/core": "2.2.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
},
"engines": {
"node": "^18.19.0 || >=20.6.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
}
},
"node_modules/@opentelemetry/semantic-conventions": {
"version": "1.40.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.40.0.tgz",
"integrity": "sha512-cifvXDhcqMwwTlTK04GBNeIe7yyo28Mfby85QXFe1Yk8nmi36Ab/5UQwptOx84SsoGNRg+EVSjwzfSZMy6pmlw==",
"license": "Apache-2.0",
"engines": {
"node": ">=14"
}
},
"node_modules/@posthog/core": {
"version": "1.23.1",
"resolved": "https://registry.npmjs.org/@posthog/core/-/core-1.23.1.tgz",
"integrity": "sha512-GViD5mOv/mcbZcyzz3z9CS0R79JzxVaqEz4sP5Dsea178M/j3ZWe6gaHDZB9yuyGfcmIMQ/8K14yv+7QrK4sQQ==",
"license": "MIT",
"dependencies": {
"cross-spawn": "^7.0.6"
}
},
"node_modules/@posthog/react": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/@posthog/react/-/react-1.8.1.tgz",
"integrity": "sha512-/tRMKPm8PKvCgmKjgKM4ojSbOpdzzKyDNK8upbK6cKedZ1wdtOcSAMiLEyNCatFB2dqwB85LcjrhkaO8lFnHNQ==",
"license": "MIT",
"peerDependencies": {
"@types/react": ">=16.8.0",
"posthog-js": ">=1.257.2",
"react": ">=16.8.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@posthog/types": {
"version": "1.356.1",
"resolved": "https://registry.npmjs.org/@posthog/types/-/types-1.356.1.tgz",
"integrity": "sha512-miIUjs4LiBDMOxKkC87HEJLIih0pNGMAjxx+mW4X7jLpN41n0PLMW7swRE6uuxcMV0z3H6MllRSCYmsokkyfuQ==",
"license": "MIT"
},
"node_modules/@protobufjs/aspromise": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
"integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/base64": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz",
"integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/codegen": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz",
"integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/eventemitter": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz",
"integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/fetch": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz",
"integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==",
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/inquire": "^1.1.0"
}
},
"node_modules/@protobufjs/float": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz",
"integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/inquire": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz",
"integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/path": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz",
"integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/pool": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz",
"integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/utf8": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz",
"integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==",
"license": "BSD-3-Clause"
},
"node_modules/@radix-ui/number": { "node_modules/@radix-ui/number": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.1.tgz",
@ -4531,7 +4186,9 @@
"version": "24.10.4", "version": "24.10.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.4.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.4.tgz",
"integrity": "sha512-vnDVpYPMzs4wunl27jHrfmwojOGKya0xyM3sH+UE5iv5uPS6vX7UIoh6m+vQc5LGBq52HBKPIn/zcSZVzeDEZg==", "integrity": "sha512-vnDVpYPMzs4wunl27jHrfmwojOGKya0xyM3sH+UE5iv5uPS6vX7UIoh6m+vQc5LGBq52HBKPIn/zcSZVzeDEZg==",
"devOptional": true,
"license": "MIT", "license": "MIT",
"peer": true,
"dependencies": { "dependencies": {
"undici-types": "~7.16.0" "undici-types": "~7.16.0"
} }
@ -5369,17 +5026,6 @@
"integrity": "sha512-RAj4E421UYRgqokKUmotqAwuplYw15qtdXfY+hGzgCJ/MBjCVZcSoHK/kH9kocfjRjcDME7IiDWR/1WX1TM2Pg==", "integrity": "sha512-RAj4E421UYRgqokKUmotqAwuplYw15qtdXfY+hGzgCJ/MBjCVZcSoHK/kH9kocfjRjcDME7IiDWR/1WX1TM2Pg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/core-js": {
"version": "3.48.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.48.0.tgz",
"integrity": "sha512-zpEHTy1fjTMZCKLHUZoVeylt9XrzaIN2rbPXEt0k+q7JE5CkCZdo6bNq55bn24a69CH7ErAVLKijxJja4fw+UQ==",
"hasInstallScript": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/core-js-compat": { "node_modules/core-js-compat": {
"version": "3.48.0", "version": "3.48.0",
"resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.48.0.tgz", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.48.0.tgz",
@ -5600,15 +5246,6 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/dompurify": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.3.1.tgz",
"integrity": "sha512-qkdCKzLNtrgPFP1Vo+98FRzJnBRGe4ffyCea9IwHB1fyxPOeNTHpLKYGd4Uk9xvNoH0ZoOjwZxNptyMwqrId1Q==",
"license": "(MPL-2.0 OR Apache-2.0)",
"optionalDependencies": {
"@types/trusted-types": "^2.0.7"
}
},
"node_modules/dunder-proto": { "node_modules/dunder-proto": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
@ -6108,12 +5745,6 @@
} }
} }
}, },
"node_modules/fflate": {
"version": "0.4.8",
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz",
"integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==",
"license": "MIT"
},
"node_modules/file-entry-cache": { "node_modules/file-entry-cache": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",
@ -7646,12 +7277,6 @@
"integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
"license": "Apache-2.0"
},
"node_modules/longest-streak": { "node_modules/longest-streak": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz",
@ -8870,38 +8495,6 @@
"node": "^10 || ^12 || >=14" "node": "^10 || ^12 || >=14"
} }
}, },
"node_modules/posthog-js": {
"version": "1.356.1",
"resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.356.1.tgz",
"integrity": "sha512-4EQliSyTp3j/xOaWpZmu7fk1b4S+J3qy4JOu5Xy3/MYFxv1SlAylgifRdCbXZxCQWb6PViaNvwRf4EmburgfWA==",
"license": "SEE LICENSE IN LICENSE",
"peer": true,
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/api-logs": "^0.208.0",
"@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
"@opentelemetry/resources": "^2.2.0",
"@opentelemetry/sdk-logs": "^0.208.0",
"@posthog/core": "1.23.1",
"@posthog/types": "1.356.1",
"core-js": "^3.38.1",
"dompurify": "^3.3.1",
"fflate": "^0.4.8",
"preact": "^10.28.2",
"query-selector-shadow-dom": "^1.0.1",
"web-vitals": "^5.1.0"
}
},
"node_modules/preact": {
"version": "10.28.4",
"resolved": "https://registry.npmjs.org/preact/-/preact-10.28.4.tgz",
"integrity": "sha512-uKFfOHWuSNpRFVTnljsCluEFq57OKT+0QdOiQo8XWnQ/pSvg7OpX5eNOejELXJMWy+BwM2nobz0FkvzmnpCNsQ==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/preact"
}
},
"node_modules/prelude-ls": { "node_modules/prelude-ls": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@ -8934,30 +8527,6 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/protobufjs": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz",
"integrity": "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg==",
"hasInstallScript": true,
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.2",
"@protobufjs/codegen": "^2.0.4",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.1.0",
"@protobufjs/float": "^1.0.2",
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.2",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0",
"@types/node": ">=13.7.0",
"long": "^5.0.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/punycode": { "node_modules/punycode": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
@ -8967,12 +8536,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/query-selector-shadow-dom": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/query-selector-shadow-dom/-/query-selector-shadow-dom-1.0.1.tgz",
"integrity": "sha512-lT5yCqEBgfoMYpf3F2xQRK7zEr1rhIIZuceDK6+xRkJQ4NMbHTwXqk4NkwDwQMNqXgG9r9fyHnzwNVs6zV5KRw==",
"license": "MIT"
},
"node_modules/randombytes": { "node_modules/randombytes": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@ -8983,9 +8546,9 @@
} }
}, },
"node_modules/react": { "node_modules/react": {
"version": "19.2.4", "version": "19.2.3",
"resolved": "https://registry.npmjs.org/react/-/react-19.2.4.tgz", "resolved": "https://registry.npmjs.org/react/-/react-19.2.3.tgz",
"integrity": "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ==", "integrity": "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA==",
"license": "MIT", "license": "MIT",
"peer": true, "peer": true,
"engines": { "engines": {
@ -8993,25 +8556,16 @@
} }
}, },
"node_modules/react-dom": { "node_modules/react-dom": {
"version": "19.2.4", "version": "19.2.3",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.4.tgz", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.3.tgz",
"integrity": "sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ==", "integrity": "sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg==",
"license": "MIT", "license": "MIT",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"scheduler": "^0.27.0" "scheduler": "^0.27.0"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^19.2.4" "react": "^19.2.3"
}
},
"node_modules/react-icons": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.6.0.tgz",
"integrity": "sha512-RH93p5ki6LfOiIt0UtDyNg/cee+HLVR6cHHtW3wALfo+eOHTp8RnU2kRkI6E+H19zMIs03DyxUG/GfZMOGvmiA==",
"license": "MIT",
"peerDependencies": {
"react": "*"
} }
}, },
"node_modules/react-markdown": { "node_modules/react-markdown": {
@ -10209,6 +9763,7 @@
"version": "7.16.0", "version": "7.16.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"devOptional": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/unicode-canonical-property-names-ecmascript": { "node_modules/unicode-canonical-property-names-ecmascript": {
@ -10594,12 +10149,6 @@
} }
} }
}, },
"node_modules/web-vitals": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-5.1.0.tgz",
"integrity": "sha512-ArI3kx5jI0atlTtmV0fWU3fjpLmq/nD3Zr1iFFlJLaqa5wLBkUSzINwBPySCX/8jRyjlmy1Volw1kz1g9XE4Jg==",
"license": "Apache-2.0"
},
"node_modules/webidl-conversions": { "node_modules/webidl-conversions": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",

View File

@ -18,7 +18,6 @@
"dev:reset-env": "cp -f .env.docker .env" "dev:reset-env": "cp -f .env.docker .env"
}, },
"dependencies": { "dependencies": {
"@posthog/react": "^1.8.1",
"@radix-ui/react-label": "^2.1.8", "@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-select": "^2.2.6", "@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-slot": "^1.2.4", "@radix-ui/react-slot": "^1.2.4",
@ -28,10 +27,8 @@
"@tanstack/react-query": "^5.90.14", "@tanstack/react-query": "^5.90.14",
"@tanstack/react-router": "^1.144.0", "@tanstack/react-router": "^1.144.0",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"posthog-js": "^1.356.1",
"react": "^19.2.0", "react": "^19.2.0",
"react-dom": "^19.2.4", "react-dom": "^19.2.0",
"react-icons": "^5.6.0",
"react-markdown": "^10.1.0", "react-markdown": "^10.1.0",
"remark-gfm": "^4.0.1", "remark-gfm": "^4.0.1",
"vite-plugin-pwa": "^1.2.0", "vite-plugin-pwa": "^1.2.0",

View File

@ -25,8 +25,7 @@ export function ArticleTicker() {
{articles.map((article, index) => ( {articles.map((article, index) => (
<Link <Link
key={`${article.id}-${index}`} key={`${article.id}-${index}`}
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors" className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors"
> >
{article.title || 'No title'} {article.title || 'No title'}
@ -35,8 +34,7 @@ export function ArticleTicker() {
{articles.map((article, index) => ( {articles.map((article, index) => (
<Link <Link
key={`dup-${article.id}-${index}`} key={`dup-${article.id}-${index}`}
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors" className="font-body text-sm uppercase tracking-wider text-background/80 hover:text-accent hover:bg-background/10 inline-block px-6 py-1 border-r border-background/20 transition-colors"
> >
{article.title || 'No title'} {article.title || 'No title'}

View File

@ -4,11 +4,12 @@ import { type SharePlatform, getPlatformLabel } from '@/lib/social-utils';
import { import {
Facebook, Facebook,
Twitter, Twitter,
MessageCircle,
Send, Send,
Mail,
Link, Link,
Share2 Share2
} from 'lucide-react'; } from 'lucide-react';
import { FaInstagram, FaTiktok } from 'react-icons/fa';
interface ShareButtonProps { interface ShareButtonProps {
platform: SharePlatform; platform: SharePlatform;
@ -51,12 +52,12 @@ export function ShareButton({
return Facebook; return Facebook;
case 'twitter': case 'twitter':
return Twitter; return Twitter;
case 'instagram': case 'whatsapp':
return FaInstagram; return MessageCircle;
case 'tiktok':
return FaTiktok;
case 'telegram': case 'telegram':
return Send; return Send;
case 'email':
return Mail;
case 'link': case 'link':
return Link; return Link;
default: default:

View File

@ -13,7 +13,7 @@ interface SocialShareButtonsProps extends ShareData {
onShare?: (platform: SharePlatform) => void; onShare?: (platform: SharePlatform) => void;
} }
const PLATFORMS: SharePlatform[] = ['facebook', 'twitter', 'instagram', 'tiktok', 'telegram', 'link']; const PLATFORMS: SharePlatform[] = ['facebook', 'twitter', 'whatsapp', 'telegram', 'email', 'link'];
export function SocialShareButtons({ export function SocialShareButtons({
articleId, articleId,
@ -54,38 +54,15 @@ export function SocialShareButtons({
onShare(platform); onShare(platform);
} }
// For Instagram and TikTok, use Web Share API if available // Open share URL in new window for social platforms
if (platform === 'instagram' || platform === 'tiktok') { if (platform !== 'link') {
if (navigator.share) {
try {
await navigator.share({
title: shareData.title,
text: shareData.excerpt,
url: shareData.url,
});
} catch (shareError) {
// User cancelled or share failed - fallback to copying link
if ((shareError as Error).name !== 'AbortError') {
const { copyToClipboard } = await import('@/lib/social-utils');
await copyToClipboard(shareData.url);
alert('Link copied! You can now paste it in ' + (platform === 'instagram' ? 'Instagram' : 'TikTok'));
}
}
} else {
// Web Share API not available - copy link as fallback
const { copyToClipboard } = await import('@/lib/social-utils');
await copyToClipboard(shareData.url);
alert('Link copied! You can now paste it in ' + (platform === 'instagram' ? 'Instagram' : 'TikTok'));
}
} else if (platform !== 'link') {
// Open share URL in new window for other social platforms
const shareUrl = getShareUrl(platform, shareData); const shareUrl = getShareUrl(platform, shareData);
window.open(shareUrl, '_blank', 'noopener,noreferrer'); window.open(shareUrl, '_blank', 'noopener,noreferrer');
} }
} catch (error) { } catch (error) {
console.error('Failed to track share:', error); console.error('Failed to track share:', error);
// Still open the share URL even if tracking fails // Still open the share URL even if tracking fails
if (platform !== 'link' && platform !== 'instagram' && platform !== 'tiktok') { if (platform !== 'link') {
const shareUrl = getShareUrl(platform, shareData); const shareUrl = getShareUrl(platform, shareData);
window.open(shareUrl, '_blank', 'noopener,noreferrer'); window.open(shareUrl, '_blank', 'noopener,noreferrer');
} }

View File

@ -122,9 +122,9 @@ export function HeroArticle() {
)} )}
<div className="flex items-center justify-between pt-4 border-t-2 border-foreground/10"> <div className="flex items-center justify-between pt-4 border-t-2 border-foreground/10">
<Link to="/articles/$id" params={{ id: article.id }}> <Link to={`/articles/${article.id}`}>
<Button variant="brutalAccent" className="gap-2"> <Button variant="brutalAccent" className="gap-2">
Прочитај повеќе Read Full Story
<ArrowRight className="w-4 h-4" /> <ArrowRight className="w-4 h-4" />
</Button> </Button>
</Link> </Link>

View File

@ -65,8 +65,7 @@ export function LatestArticlesGrid() {
className={`group border-brutal-sm bg-card hover:shadow-brutal transition-all duration-150 hover:-translate-y-1 animate-fade-in-up stagger-${Math.min(index + 1, 12)}`} className={`group border-brutal-sm bg-card hover:shadow-brutal transition-all duration-150 hover:-translate-y-1 animate-fade-in-up stagger-${Math.min(index + 1, 12)}`}
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block" className="block"
> >
{article.featuredImage ? ( {article.featuredImage ? (
@ -108,12 +107,12 @@ export function LatestArticlesGrid() {
</span> </span>
{article.category && ( {article.category && (
<a <Link
href={`/${article.category.slug}`} to={`/${article.category.slug}`}
className="px-2 py-0.5 border border-foreground bg-background text-foreground text-[10px] hover:bg-accent hover:border-accent transition-colors" className="px-2 py-0.5 border border-foreground bg-background text-foreground text-[10px] hover:bg-accent hover:border-accent transition-colors"
> >
{article.category.name} {article.category.name}
</a> </Link>
)} )}
</div> </div>
@ -122,7 +121,7 @@ export function LatestArticlesGrid() {
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -39,8 +39,7 @@ export function ArchiveComponent() {
className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow" className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow"
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block mb-4" className="block mb-4"
> >
<h2 className="text-xl font-semibold mb-2 line-clamp-2"> <h2 className="text-xl font-semibold mb-2 line-clamp-2">
@ -70,7 +69,7 @@ export function ArchiveComponent() {
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -42,7 +42,7 @@ export function ArticleDetailComponent({ id }: { id: string }) {
return ( return (
<article className="max-w-3xl mx-auto"> <article className="max-w-3xl mx-auto">
<Link <Link
to="/archive" to="/articles"
className="inline-flex items-center gap-2 text-muted-foreground hover:text-foreground mb-8" className="inline-flex items-center gap-2 text-muted-foreground hover:text-foreground mb-8"
> >
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
@ -78,7 +78,7 @@ export function ArticleDetailComponent({ id }: { id: string }) {
articleId={data.id} articleId={data.id}
title={data.title} title={data.title}
url={typeof window !== 'undefined' ? window.location.href : ''} url={typeof window !== 'undefined' ? window.location.href : ''}
excerpt={data.excerpt ?? undefined} excerpt={data.excerpt}
image={data.featuredImage} image={data.featuredImage}
tags={data.tags} tags={data.tags}
/> />
@ -151,14 +151,10 @@ export function ArticleDetailComponent({ id }: { id: string }) {
)} )}
<div className="prose prose-slate max-w-none"> <div className="prose prose-slate max-w-none">
<div className="text-lg leading-relaxed mb-6 text-justify"> <div className="text-lg leading-relaxed mb-6">
<ReactMarkdown <ReactMarkdown
remarkPlugins={[remarkGfm]} remarkPlugins={[remarkGfm]}
components={{ components={{
p: (props) => <p {...props} className="mb-4 text-justify" />,
ul: (props) => <ul {...props} className="list-disc list-outside ml-6 mb-4 space-y-2" />,
ol: (props) => <ol {...props} className="list-decimal list-outside ml-6 mb-4 space-y-2" />,
li: (props) => <li {...props} className="text-justify" />,
img: (props) => ( img: (props) => (
<img <img
{...props} {...props}
@ -202,7 +198,7 @@ export function ArticleDetailComponent({ id }: { id: string }) {
articleId={data.id} articleId={data.id}
title={data.title} title={data.title}
url={typeof window !== 'undefined' ? window.location.href : ''} url={typeof window !== 'undefined' ? window.location.href : ''}
excerpt={data.excerpt ?? undefined} excerpt={data.excerpt}
image={data.featuredImage} image={data.featuredImage}
tags={data.tags} tags={data.tags}
variant="footer" variant="footer"

View File

@ -57,7 +57,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
{/* Hero Article - 2/3 width */} {/* Hero Article - 2/3 width */}
<div className="lg:col-span-2"> <div className="lg:col-span-2">
<div className="rounded-xl border bg-card overflow-hidden group hover:shadow-lg transition-shadow"> <div className="rounded-xl border bg-card overflow-hidden group hover:shadow-lg transition-shadow">
<Link to="/articles/$id" params={{ id: heroArticle.id }} className="block"> <Link to={`/articles/${heroArticle.id}`} className="block">
{heroArticle.featuredImage ? ( {heroArticle.featuredImage ? (
<div className="relative h-64 md:h-80 overflow-hidden"> <div className="relative h-64 md:h-80 overflow-hidden">
<img <img
@ -80,7 +80,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
</Link> </Link>
<div className="p-6"> <div className="p-6">
<Link to="/articles/$id" params={{ id: heroArticle.id }} className="block"> <Link to={`/articles/${heroArticle.id}`} className="block">
<h2 className="text-2xl font-bold mb-3 group-hover:text-primary transition-colors"> <h2 className="text-2xl font-bold mb-3 group-hover:text-primary transition-colors">
{heroArticle.title} {heroArticle.title}
</h2> </h2>
@ -108,7 +108,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
articleId={heroArticle.id} articleId={heroArticle.id}
title={heroArticle.title} title={heroArticle.title}
url={`${window.location.origin}/articles/${heroArticle.id}`} url={`${window.location.origin}/articles/${heroArticle.id}`}
excerpt={heroArticle.excerpt ?? undefined} excerpt={heroArticle.excerpt}
image={heroArticle.featuredImage} image={heroArticle.featuredImage}
tags={heroArticle.tags} tags={heroArticle.tags}
variant="compact" variant="compact"
@ -135,8 +135,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow group" className="p-6 rounded-xl border bg-card hover:shadow-lg transition-shadow group"
> >
<Link <Link
to="/articles/$id" to={`/articles/${article.id}`}
params={{ id: article.id }}
className="block mb-4" className="block mb-4"
> >
<h2 className="text-xl font-semibold mb-2 line-clamp-2 group-hover:text-primary transition-colors"> <h2 className="text-xl font-semibold mb-2 line-clamp-2 group-hover:text-primary transition-colors">
@ -166,7 +165,7 @@ export function CategoryPage({ categorySlug, categoryName, categoryDescription }
articleId={article.id} articleId={article.id}
title={article.title} title={article.title}
url={`${window.location.origin}/articles/${article.id}`} url={`${window.location.origin}/articles/${article.id}`}
excerpt={article.excerpt ?? undefined} excerpt={article.excerpt}
image={article.featuredImage} image={article.featuredImage}
tags={article.tags} tags={article.tags}
variant="compact" variant="compact"

View File

@ -32,10 +32,19 @@ export function NotificationBanner() {
}; };
const handleSubscribe = async () => { const handleSubscribe = async () => {
console.log('handleSubscribe called');
console.log('isSupported:', isSupported);
console.log('isSubscribed:', isSubscribed);
try {
const success = await subscribe(); const success = await subscribe();
console.log('subscribe() returned:', success);
if (success) { if (success) {
setIsVisible(false); setIsVisible(false);
} }
} catch (error) {
console.error('handleSubscribe error:', error);
}
}; };
if (!isVisible || isSubscribed || isDismissed) { if (!isVisible || isSubscribed || isDismissed) {

View File

@ -18,8 +18,8 @@ function checkPushSupport(): boolean {
); );
} }
function getInitialPermission(): NotificationPermission { function getInitialPermission(): NotificationPermission | 'not-supported' {
if (!checkPushSupport()) return 'denied'; if (!checkPushSupport()) return 'not-supported';
return Notification.permission; return Notification.permission;
} }
@ -27,7 +27,7 @@ export interface UsePushNotificationsReturn {
isSupported: boolean; isSupported: boolean;
isSubscribed: boolean; isSubscribed: boolean;
isLoading: boolean; isLoading: boolean;
permissionState: NotificationPermission; permissionState: NotificationPermission | 'not-supported';
subscribe: () => Promise<boolean>; subscribe: () => Promise<boolean>;
unsubscribe: () => Promise<boolean>; unsubscribe: () => Promise<boolean>;
requestPermission: () => Promise<NotificationPermission>; requestPermission: () => Promise<NotificationPermission>;
@ -40,21 +40,30 @@ export function usePushNotifications(): UsePushNotificationsReturn {
const [permissionState, setPermissionState] = useState(getInitialPermission); const [permissionState, setPermissionState] = useState(getInitialPermission);
const hasCheckedRef = useRef(false); const hasCheckedRef = useRef(false);
useEffect(() => {
console.log('usePushNotifications - isSupported:', checkPushSupport());
console.log('usePushNotifications - permissionState:', getInitialPermission());
}, []);
useEffect(() => { useEffect(() => {
if (!isSupported || hasCheckedRef.current) return; if (!isSupported || hasCheckedRef.current) return;
hasCheckedRef.current = true; hasCheckedRef.current = true;
console.log('Checking existing push subscription...');
navigator.serviceWorker.ready navigator.serviceWorker.ready
.then((registration) => registration.pushManager.getSubscription()) .then((registration) => registration.pushManager.getSubscription())
.then((subscription) => { .then((subscription) => {
console.log('Existing subscription:', subscription);
setIsSubscribed(!!subscription); setIsSubscribed(!!subscription);
}) })
.catch(() => {}); .catch((error) => {
console.error('Error checking subscription:', error);
});
}, [isSupported]); }, [isSupported]);
const requestPermission = const requestPermission =
useCallback(async (): Promise<NotificationPermission> => { useCallback(async (): Promise<NotificationPermission> => {
if (!isSupported) return 'denied'; if (!isSupported) return 'not-supported';
const permission = await Notification.requestPermission(); const permission = await Notification.requestPermission();
setPermissionState(permission); setPermissionState(permission);
@ -69,26 +78,38 @@ export function usePushNotifications(): UsePushNotificationsReturn {
try { try {
const permission = await requestPermission(); const permission = await requestPermission();
if (permission !== 'granted') { if (permission !== 'granted') {
console.log('Push permission denied');
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
const publicKey = await getVapidPublicKey(); const publicKey = await getVapidPublicKey();
if (!publicKey) { if (!publicKey) {
console.error('VAPID public key not available');
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
console.log('Got VAPID public key, subscribing...');
// Check if service worker is already ready
console.log('Checking service worker status...');
const swController = navigator.serviceWorker.controller;
console.log('Service worker controller:', swController);
// Wait for service worker to be ready with timeout
const registration = await Promise.race([ const registration = await Promise.race([
navigator.serviceWorker.ready, navigator.serviceWorker.ready,
new Promise<ServiceWorkerRegistration>((_, reject) => { new Promise<ServiceWorkerRegistration>((_, reject) => {
setTimeout(() => { setTimeout(() => {
reject(new Error('Service worker ready timeout')); reject(new Error('Service worker ready timeout after 10s'));
}, 10000); }, 10000);
}), }),
]); ]);
console.log('Service worker ready:', registration);
if (!registration.pushManager) { if (!registration.pushManager) {
console.error('PushManager not available in service worker registration');
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
@ -96,25 +117,31 @@ export function usePushNotifications(): UsePushNotificationsReturn {
let subscription = await registration.pushManager.getSubscription(); let subscription = await registration.pushManager.getSubscription();
if (!subscription) { if (!subscription) {
const keyArray = urlBase64ToUint8Array(publicKey); console.log('Creating new push subscription...');
subscription = await registration.pushManager.subscribe({ subscription = await registration.pushManager.subscribe({
userVisibleOnly: true, userVisibleOnly: true,
applicationServerKey: keyArray.buffer as ArrayBuffer, applicationServerKey: urlBase64ToUint8Array(publicKey),
}); });
console.log('Push subscription created');
} else {
console.log('Existing push subscription found');
} }
const subJson = subscription.toJSON(); const subJson = subscription.toJSON();
console.log('Subscription JSON:', subJson);
if ( if (
!subJson.endpoint || !subJson.endpoint ||
!subJson.keys?.p256dh || !subJson.keys?.p256dh ||
!subJson.keys?.auth !subJson.keys?.auth
) { ) {
console.error('Invalid subscription data:', subJson);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
const success = await subscribeToPush(subJson as PushSubscriptionData); const success = await subscribeToPush(subJson as PushSubscriptionData);
console.log('Subscribe to push result:', success);
if (success) { if (success) {
setIsSubscribed(true); setIsSubscribed(true);
@ -123,7 +150,8 @@ export function usePushNotifications(): UsePushNotificationsReturn {
setIsLoading(false); setIsLoading(false);
return success; return success;
} catch { } catch (error) {
console.error('Error subscribing to push notifications:', error);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
@ -147,7 +175,8 @@ export function usePushNotifications(): UsePushNotificationsReturn {
localStorage.removeItem(STORAGE_KEY); localStorage.removeItem(STORAGE_KEY);
setIsLoading(false); setIsLoading(false);
return true; return true;
} catch { } catch (error) {
console.error('Error unsubscribing from push notifications:', error);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }

View File

@ -20,7 +20,8 @@ export async function getVapidPublicKey(): Promise<string | null> {
} }
const data: VapidPublicKeyResponse = await response.json(); const data: VapidPublicKeyResponse = await response.json();
return data.publicKey; return data.publicKey;
} catch { } catch (error) {
console.error('Error fetching VAPID public key:', error);
return null; return null;
} }
} }
@ -29,20 +30,39 @@ export async function subscribeToPush(
subscription: PushSubscriptionData, subscription: PushSubscriptionData,
): Promise<boolean> { ): Promise<boolean> {
try { try {
console.log('Sending subscription to server:', {
endpoint: subscription.endpoint,
hasKeys: !!subscription.keys,
});
const payload = {
endpoint: subscription.endpoint,
p256dh: subscription.keys.p256dh,
auth: subscription.keys.auth,
};
console.log('Payload:', payload);
console.log('API URL:', `${API_BASE_URL}/push/subscribe`);
const response = await fetch(`${API_BASE_URL}/push/subscribe`, { const response = await fetch(`${API_BASE_URL}/push/subscribe`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ body: JSON.stringify(payload),
endpoint: subscription.endpoint,
p256dh: subscription.keys.p256dh,
auth: subscription.keys.auth,
}),
}); });
return response.ok; console.log('Subscribe response status:', response.status);
} catch {
if (!response.ok) {
const errorText = await response.text();
console.error('Subscribe failed:', errorText);
return false;
}
return true;
} catch (error) {
console.error('Error subscribing to push:', error);
return false; return false;
} }
} }
@ -59,7 +79,8 @@ export async function unsubscribeFromPush(
body: JSON.stringify({ endpoint }), body: JSON.stringify({ endpoint }),
}); });
return response.ok; return response.ok;
} catch { } catch (error) {
console.error('Error unsubscribing from push:', error);
return false; return false;
} }
} }

Some files were not shown because too many files have changed in this diff Show More