Skip to content

MBSM110/stak-task

Repository files navigation

Cloudflare Worker + Firestore Itinerary API

A serverless API using Cloudflare Workers and Firestore to generate AI-based travel itineraries with the OpenAI API.


Installation & Usage

1. Clone the Repository

git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>

2. Install Dependencies

npm install

3. Set Environment Variables

Create a .env file in the root directory with:

OPENAI_API_KEY=your-openai-api-key
FIREBASE_PROJECT_ID=your-firestore-project-id
FIREBASE_CLIENT_EMAIL=your-firebase-service-account-email
FIREBASE_PRIVATE_KEY="your-firebase-private-key"

Note: You can get these values from your Firebase Service Account JSON file in the Google Cloud Console.

4. Add Firestore to Your Worker

  1. In the Firebase Console, create a Firestore database (Native mode).
  2. Create a collection called itineraries.
  3. Give your Firebase service account read/write access.
  4. Add the credentials from your service account to your worker using environment variables.

5. Deploy to Cloudflare

npx wrangler login
npx wrangler publish

Architecture Overview

Stak-task/
│
├── src/
│   ├── index.js         <-- main worker logic
│   ├── firebase.js      <-- Firestore access & token management
│   ├── routes.js        <-- request routing / endpoint handlers
│   └── utils.js         <-- helper functions (optional)
│
├── wrangler.toml        <-- Cloudflare Worker configuration
├── package.json         <-- dependencies & scripts
├── .env.example         <-- example environment variables
└── README.md            <-- project documentation

API Endpoints

POST /** — Create a new itinerary

Windows CMD Example

curl -X POST "https://stak-task.mbagher.workers.dev/itinerary" -H "Content-Type: application/json" -d "{\"destination\":\"Rasht, Iran\", \"durationDays\":5}"

Linux / macOS Example

curl -X POST "https://stak-task.mbagher.workers.dev/itinerary" -H "Content-Type: application/json" -d '{"destination":"Rasht, Iran", "durationDays":5}'

Example Response

{
  "jobId": "uuid-generated-id"
}

Status: 202 Accepted


GET /itinerary/:jobId — Retrieve the itinerary by job ID

Windows CMD Example

curl -X GET "https://stak-task.mbagher.workers.dev/itinerary/<jobId>"

Linux / macOS Example

curl -X GET "https://stak-task.mbagher.workers.dev/itinerary/<jobId>"

Example Response

{
  "status": "completed",
  "destination": "Paris, France",
  "durationDays": 3,
  "createdAt": "Firestore Timestamp",
  "completedAt": "Firestore Timestamp",
  "itinerary": [
    {
      "day": 1,
      "theme": "Historical Paris",
      "activities": [
        {
          "time": "Morning",
          "description": "Visit the Louvre Museum. Pre-book tickets to avoid queues.",
          "location": "Louvre Museum"
        }
      ]
    }
  ],
  "error": null
}

About

The AI-Powered Itinerary Generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors