A Val Town application for managing and viewing demos with authentication.
This application uses LastLogin for authentication:
/auth/logout
(handled automatically by LastLogin)The following routes are accessible without authentication:
/api/health
- System health statusRoutes are protected by different authentication mechanisms:
User Authentication (Google OAuth via LastLogin):
/
- Main dashboard (shows user info and system status)/api/*
- API endpoints (except health)/views/*
- View routes including /views/glimpse/:id
/glimpse/*
- Shortcut routes including /glimpse/:id
(equivalent to /views/glimpse/:id
)Webhook Authentication (X-API-KEY header):
/tasks/*
- Webhook endpoints for external integrations (POST requests only)
/tasks/*
are allowed without authentication for debug endpoints├── backend/
│ ├── controllers/ # Business logic controllers
│ ├── routes/ # Route definitions and HTTP handling
│ │ ├── api/ # API endpoints
│ │ ├── glimpse/ # Shortcut glimpse routes
│ │ ├── tasks/ # Task-related routes
│ │ ├── views/ # User-facing views
│ │ └── authCheck.ts # Authentication middleware
│ └── services/ # External service integrations
├── frontend/ # Frontend assets
├── shared/ # Shared utilities
└── main.tsx # Application entry point
The application follows a clean MVC architecture with proper separation of concerns:
All controller functions return a consistent structure:
{
success: boolean,
data: any | null,
error: string | null,
details?: string // Additional error context
}
Routes then format these into appropriate HTTP responses.
The application provides multiple routes for accessing page data and user authentication:
GET /glimpse/login
- User-specific login redirect
GLANCE_DEMOS_DB_ID
database/glimpse/thanks
GET /glimpse/thanks
- New user welcome page
GET /views/glimpse/:id
- Get complete page data with blocks by Notion page IDGET /glimpse/:id
- Same functionality as above, shorter URLNote: As of the latest update, glimpse endpoints now return complete page data including all blocks recursively fetched from Notion. This provides richer content compared to the previous properties-only behavior.
API endpoints for accessing Notion page data with different levels of detail:
GET /api/demo/:id/properties
- Returns page properties onlyGET /api/demo/:id
- Returns page properties + all blocks recursivelyArchitecture:
getDemoProperties
, getDemoFull
)Authentication Behavior:
Response Format: Routes return the data directly from controllers on success:
{ // Notion page object with properties // For full endpoint: also includes "blocks" array with recursive block data }
On error, routes return:
{ "error": "Error message", "details": "Additional error context" }
Usage Examples:
// Internal call from within Val (no authentication needed)
const response = await fetch('/api/demo/page-id/properties');
const data = await response.json();
// External browser request (requires authentication)
// User must be logged in via Google OAuth
All glimpse routes:
GLANCE_DEMOS_DB_ID
database for user's email/glimpse/thanks
with next steps information/glimpse/login
once URL is configuredThe GLANCE_DEMOS_DB_ID
database must contain:
Supported URL property names: URL
, Link
, Redirect URL
, Demo URL
, url
, link
Supported URL property types: url
, rich_text
, title
The login endpoint provides detailed error information for debugging:
The dashboard displays both routes in a comparison table for easy testing.
The application is built with:
The application supports webhook endpoints for external integrations (like Notion webhooks):
Set the webhook secret in your environment:
NOTION_WEBHOOK_SECRET=your-secret-key-here
POST /tasks/notion-webhook
- Main webhook endpoint for Notion integrations (requires X-API-KEY
header)POST /tasks/url
- Updates Notion page URL property with glimpse URL (requires X-API-KEY
header)POST /tasks/test
- Test endpoint for webhook authentication (requires X-API-KEY
header)GET /tasks/debug-webhook
- Debug endpoint to check webhook configurationWebhook endpoints require the X-API-KEY
header:
curl -X POST https://your-val.web.val.run/tasks/test \ -H "X-API-KEY: your-secret-key-here"
Use the webhook testing form in the dashboard:
/
NOTION_WEBHOOK_SECRET
valueConfigure these environment variables for full functionality:
GLANCE_DEMOS_DB_ID
- Notion database ID for demosGLANCE_CONTENT_DB_ID
- Notion database ID for contentGLANCE_INTERACTIONS_DB_ID
- Notion database ID for interactionsNOTION_API_KEY
- Notion API key for database accessNOTION_WEBHOOK_SECRET
- Secret key for webhook authentication