Skip to content

API Services Documentation

Overview

The API services directory (api/) contains server-side Express.js endpoints that handle various backend operations, including file uploads, cloud storage integrations, payment processing, and search functionality.

API Structure

All API endpoints are mounted as server middleware in nuxt.config.js:

javascript
serverMiddleware: [
  { path: '/api', handler: '~/api/index.js' },
  { path: '/s3', handler: '~/api/s3.js' },
  { path: '/driveapi', handler: '~/api/drive-api.js' },
  { path: '/box', handler: '~/api/box.js' },
  { path: '/zip', handler: '~/api/zip-viewer.js' },
  { path: '/convert', handler: '~/api/media-converter' },
  { path: '/stripe', handler: '~/api/payments.js' },
  { path: '/typesense', handler: '~/api/typesense.js' },
  // ... more endpoints
]

API Services

Main API

  • Path: api/index.js
  • Base Path: /api
  • Purpose: General API endpoints

Endpoints

  • GET /api/browser-os - Get browser and OS information
  • GET /api/image-proxy - Proxy images from external URLs
  • POST /api/upload-asset - Upload asset via server

S3 Service

  • Path: api/s3.js
  • Base Path: /s3
  • Purpose: AWS S3 file storage operations

Endpoints

  • GET /s3/getBucketConfig - Get S3 bucket CORS configuration
  • POST /s3/updateBucketConfig - Update S3 bucket CORS configuration
  • GET /s3/start-upload - Initiate multipart upload
  • GET /s3/get-upload-url - Get presigned URL for chunk upload
  • POST /s3/complete-upload - Complete multipart upload
  • GET /s3/download - Download file from S3
  • DELETE /s3/delete - Delete file from S3

Google Drive API

  • Path: api/drive-api.js
  • Base Path: /driveapi
  • Purpose: Google Drive integration

Endpoints

  • GET /driveapi/auth - Initiate Google Drive authentication
  • GET /driveapi/callback - Handle OAuth callback
  • GET /driveapi/files - List Drive files
  • POST /driveapi/upload - Upload to Drive
  • GET /driveapi/download - Download from Drive

Dropbox API

  • Path: api/dropbox.js (if exists)
  • Base Path: /dropbox
  • Purpose: Dropbox integration

Box API

  • Path: api/box.js
  • Base Path: /box
  • Purpose: Box.com integration

Endpoints

  • GET /box/auth - Initiate Box authentication
  • GET /box/callback - Handle OAuth callback
  • GET /box/files - List Box files
  • POST /box/upload - Upload to Box

Typesense API

  • Path: api/typesense.js
  • Base Path: /typesense
  • Purpose: Search engine integration

Endpoints

  • POST /typesense/search-assets - Search assets
  • POST /typesense/search-folders - Search folders
  • POST /typesense/search-collages - Search collages
  • GET /typesense/suggestions - Get search suggestions

Payment API

  • Path: api/payments.js
  • Base Path: /stripe
  • Purpose: Stripe payment processing

Endpoints

  • POST /stripe/create-checkout - Create checkout session
  • POST /stripe/webhook - Handle Stripe webhooks
  • GET /stripe/subscription - Get subscription details

Media Converter

  • Path: api/media-converter/index.js
  • Base Path: /convert
  • Purpose: Media file conversion

Endpoints

  • POST /convert/video - Convert video format
  • POST /convert/image - Convert image format
  • GET /convert/status/:id - Get conversion status

Zip Viewer

  • Path: api/zip-viewer.js
  • Base Path: /zip
  • Purpose: ZIP file handling

Endpoints

  • GET /zip/list - List ZIP contents
  • GET /zip/extract - Extract ZIP file
  • GET /zip/download - Download ZIP file

Shared Assets API

  • Path: api/shared/index.js
  • Base Path: /shared
  • Purpose: Shared asset operations
  • Path: api/universal-link.js
  • Base Path: /apple-app-site-association
  • Purpose: iOS universal links

Image Generation API

  • Path: api/generate-image.js
  • Base Path: /generate-image
  • Purpose: AI image generation

Phone Number API

  • Path: api/phone-number.js
  • Base Path: /phone-number
  • Purpose: Phone number validation

Authentication

Most API endpoints require authentication:

  • Token-based authentication via Authorization header
  • Token validation against backend API
  • User workspace validation

Error Handling

All endpoints implement consistent error handling:

javascript
try {
  // API logic
  res.send({ success: true, data: result })
} catch (error) {
  res.status(500).send({ 
    error: error.message,
    stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
  })
}

CORS Configuration

All endpoints support CORS:

javascript
app.use(cors({
  origin: '*',
  exposedHeaders: 'ETAG',
  allowedHeaders: '*'
}))

Environment Variables

API services require these environment variables:

  • AWS_ACCESS_KEY_ID - AWS access key
  • AWS_SECRET_ACCESS_KEY - AWS secret key
  • AWS_BUCKET - S3 bucket name
  • AWS_DEFAULT_REGION - AWS region
  • GOOGLE_DRIVE_CLIENT_ID - Google Drive client ID
  • GOOGLE_DRIVE_CLIENT_SECRET - Google Drive secret
  • STRIPE_SECRET_KEY - Stripe secret key
  • TYPESENSE_HOST - Typesense host
  • TYPESENSE_API_KEY - Typesense API key