This is the AFI Explorer API, a serverless API built using Cloudflare Workers. It periodically fetches and caches data from the U.S. Air Force e-Publishing website and serves it through various endpoints.
Before you begin, ensure you have the following installed on your local machine:
- Node.js (version 16.x or higher)
- NPM (version 7.x or higher)
- Cloudflare Account
- Wrangler CLI
These instructions will help you set up a Cloudflare account, configure your environment, and deploy the Worker.
-
Create a Cloudflare Account:
Visit Cloudflare Sign-Up and create a new account if you do not have one already.
-
Access Cloudflare Workers:
After signing in, go to your Cloudflare dashboard. On the left sidebar, click on "Workers" to access Cloudflare Workers.
Wrangler is a command-line tool for managing Cloudflare Workers.
npm install -g wranglerRun the following command to log in to your Cloudflare account:
wrangler loginThis will open a browser window for you to authenticate Wrangler with your Cloudflare account.
-
Extract the Project Files:
Once you have the ZIP archive of the source code, unzip the contents. Make sure that you are in the
api/directory where the project files are located. -
Install Dependencies:
Run the following command to install the project dependencies:
npm install
-
Create a KV Namespace:
- Go to the Cloudflare dashboard.
- Navigate to Workers KV > Create Namespace and create a new namespace.
- Note down the namespace ID as you will need it for the configuration.
-
Update
wrangler.toml:Replace
your_kv_namespace_id_herewith your actual KV namespace ID in theapi/wrangler.tomlfile.
Submit the following command to deploy your Cloudflare Worker:
npm run deployThis will bundle and upload your Worker script to Cloudflare. It will be available at a persistent *.workers.dev domain that you can access from user applications.
Once deployed, the Worker will automatically fetch and cache data according to the specified cron schedule (every 10 minutes). Please note that the KV store will need to be "seeded," so data may not appear, or will appear incomplete, until all scheduled cron jobs have run at least once.
Use the following command to run the Worker in development mode:
npm startWrangler will run your Worker on http://localhost:8787.
Following these steps should help you set up and deploy your Cloudflare Worker successfully. If you encounter any issues, refer to the Cloudflare Workers Documentation.