appwrite-fn-import-geojson
v1.2.0
Published
An Appwrite function which can receive and process a GeoJSON FeatureCollection of cadastral parcels, as a slice of a larger collection. Each parcel is stored as an individual record in a database, and the resulting, complete collection is rebuilt, cached
Readme
appwrite-fn-import-geojson
An Appwrite function which can receive and process a GeoJSON FeatureCollection of cadastral parcels, as a slice of a larger collection. Each parcel is stored as an individual record in a database, and the resulting, complete collection is rebuilt, cached and exposed as a static asset.
This README explains how to develop and test the Appwrite import function locally, using Docker for the Appwrite stack (function, database, API key) and a mock GeoJSON FeatureCollection payload.
Prerequisites
- Docker
- Node.js (v16+)
- Appwrite CLI (for project setup & deployment)
1. Start Appwrite locally
You need a local Appwrite instance with a database and a placeholder function configured. It’s all managed by Docker Compose.
- In a directory (inside this very repo, or somewhere else), follow the official Appwrite Docker install guide to install the stack:
docker run -it --rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
--entrypoint="install" \
appwrite/appwrite:1.7.4It generates ./appwrite/docker-compose.yml.
Add ./appwrite/.env (copy/paste https://appwrite.io/install/env).
Then, simply run docker compose up -d --remove-orphans.
TODO: automate most if not all the next steps
Access the Appwrite console at http://localhost:80 and create:
- A user account
- A project
- A database (no collection required)
- A Node v18+ placeholder (empty) function named "import-geojson" (it’s source code will be linked to this very repository)
- A "localhost-cli" API key which must grant full access to everything (used by CLI commands for setting things up, debugging, etc.)
Edit appwrite.config.json to use the proper $id values for the project, its database and the placeholder function (beware, some values appear multiple times).
Create a placeholder (empty) functions named "import-geojson". Enter the function, and add a custom domain "import-geojson.functions.localhost".
Set the following environment variables in the function:
APPWRITE_ENDPOINT(e.g. "http://appwrite/v1" or a live endpoint; don’t use "http://localhost/v1" for it must use docker compose’s services’ names, it’s not for external resolution from your host machine but for an Appwrite service to communicate to another)APPWRITE_PROJECT_ID
APPWRITE_DB_IDAPPWRITE_TABLE_NAME(e.g. "parcels")
Connect the placeholder function to this very source code, by deploying it and thus creating a first dockerized deployment:
appwrite client --endpoint http://localhost/v1 --self-signed true --project-id [PROJECT_ID] --key [SECRET_VALUE_FOR_KEY_localhost-cli]
# appwrite login # do not login, we’re using an API key instead
# appwrite functions list # you may check the cli has been properly configured2. Push (deploy) the function
npm run appwrite:pushRunning the Function on the host
For pure local testing, you may run the function on your host rather than inside Docker:
npx ts-node src/index.tsIt’s outside Appwrite’s stack though, so YMMV.
3. Send a Mock Excel file
- Use the provided script to send a test payload to your locally deployed function:
npm run test:import-excel3. Verify Data in Appwrite
- Use the Appwrite console or API to check that documents have been created in a collection.
Troubleshooting
- Ensure all required environment variables are set.
- Check Docker logs if the Appwrite stack is not responding.
- Check Appwrite’s console (function logs).
For more details, see the Appwrite documentation: https://appwrite.io/docs/
