Skip to content

Refactor generateSnakeAnimation for serverless compatibility (Vercel-ready API support)#204

Open
qianyu15 wants to merge 7 commits into
Platane:mainfrom
qianyu15:support_vercel
Open

Refactor generateSnakeAnimation for serverless compatibility (Vercel-ready API support)#204
qianyu15 wants to merge 7 commits into
Platane:mainfrom
qianyu15:support_vercel

Conversation

@qianyu15

@qianyu15 qianyu15 commented Jul 5, 2026

Copy link
Copy Markdown

Summary

This PR refactors the snake generation pipeline to improve compatibility with serverless environments (e.g. Vercel) and prepares the project for potential API usage.

Motivation

The current implementation is CLI-first and relies on execution patterns that are not suitable for serverless environments:

  • child_process usage
  • CLI-based execution flow
  • implicit filesystem / runtime assumptions (depending on execution path)

This makes it difficult to expose functionality as a HTTP API endpoint.

Changes

  • Refactored generateSnakeAnimation flow to reduce CLI coupling
  • Improved separation between:
    • core snake generation logic
    • CLI execution layer
  • Adjusted output flow to allow in-memory SVG generation

Impact

  • Enables potential usage in serverless environments (e.g. Vercel API routes)
  • Improves modularity of snake generation pipeline
  • Prepares codebase for future API wrapper layer

Notes

This is an incremental refactor, not a full architectural rewrite.
CLI compatibility is preserved.

Future Work

  • Introduce official API wrapper (generateSnakeSvg(user))
  • Fully remove runtime dependencies from core logic if needed
  • Add caching strategy for API usage

qianyu15 added 7 commits July 5, 2026 21:16
- Keep core function pure and serverless-compatible
- Returns in-memory strings for both SVG and GIF formats
- No filesystem or child_process usage
- Maintains identical behavior for actual generation
Refactor generateSnakeAnimation to use OutputConfig type and update return handling for null outputs.
Update generateSnakeAnimation function signature and types
Revert "Update generateSnakeAnimation function signature and types"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant