A simple Netlify serverless API using TypeScript and the sweph package to calculate planetary positions, ascendant, and midheaven.
simple-astro-api/
├── tsconfig.json # TypeScript configuration
├── netlify.toml # Netlify configuration
├── package.json # Dependencies
└── functions/
└── astro-api.ts # Express app as serverless function
Returns planetary positions, ascendant, and midheaven for a given date, time, and location.
Query Parameters:
date: Date in YYYY-MM-DD formattime: Time in HH:MM:SS format (24-hour)lat: Latitude in decimal degreeslng: Longitude in decimal degreeshouse_system: House system character in sweph format (default: W)
Example Request:
/api/positions?date=2023-01-01&time=12:00:00&lat=40.7128&lng=-74.0060&house_system=O
Health check endpoint to verify the API is running.
-
Install dependencies:
npm install -
Install Netlify CLI (if not already installed):
npm install netlify-cli -g -
You'll need to download Swiss Ephemeris files and set the path:
- Download ephemeris files from https://www.astro.com/ftp/swisseph/ephe/
- Create an
ephemerisdirectory in the functions directory and place the files there - Or set the
SWEPH_PATHenvironment variable to point to your ephemeris files
-
Build the TypeScript code:
npm run build -
Run locally:
npm run dev
-
Connect to your Netlify account:
netlify login -
Deploy to Netlify:
netlify deploy --prod
Note: For production deployment, you'll need to include the ephemeris files with your function. Make sure to copy them to the dist/functions/ephemeris directory during the build process.