It is a common scenario for us to build a data visualization site with small datasets in the form of CSV/JSON files. But then the client wants to have a database interface to update the data from time to time. In this case, we think that using a backend with an API... is a waste of resources when all you need is just a CSV/JSON.
So the solution we found is to use SeaTable: as a headless CMS. SeaTable is a kind of Airtable but European, GDPR compliant, and with many interesting features.
But it is not really a database intended to be used as a backend: We don’t want to connect each visitor's browser directly with the database.
So we just needed a way to download the data from the database and save it as a JSON file. Then we can use this JSON file in the build process to generate a static site with NUXT or NEXT for instance.
Since we use Netlify as our primary hosting solution, we created a Netlify build plugin that downloads the data from SeaTable before each build.
This plugin is available here:
https://github.com/thegraphicmethod/netlify-plugin-seatable
It is not officially supported by SeaTable. It is a plugin we created for our own needs and we are sharing it in case it can be useful for someone else. But please, do some testing before moving to production, we need more users to be sure that it works in all cases.
How to use it
install the plugin with npm:
npm install -D netlify-plugin-seatable
Go to your SeaTable admin panel and get the API key for the base you want to use. You can get the API Key for a Base in the advanced section of the base settings.
In your application, add a netlify.toml file with the following content:
[[plugins]]
package = "netlify-plugin-seatable"
# Plugin configuration
[plugins.inputs]
SEATABLE_TABLE_NAME = "Table1,Table2"
DATA_FOLDER = "assets/data"
SEATABLE_TABLE_NAME could be a single table name or multiple table names separated by a comma (no spaces between names)
For each table, a JSON file will be created in the DATA_FOLDER folder.
- Since the API token is a secret, it is not recommended to have it in your repository. So, in the Netlify app add the following environment variable:
SEATABLE_APP_TOKEN (which is the token of the Seatable app)
- That’s it. Now each time you build your site the plugin will download the data from SeaTable BEFORE BUILDING and will save it in the specified folder.
Please note that the DATA_FOLDER must exist in the repository. The plugin will not create it.
Also, note that the plugin will overwrite the JSON file if it already exists but it won't commit to the repository. It is only available during the build process.
Feedback
This is our first Netlify plugin so any feedback is welcome. Let us know if you find it useful or if you have any suggestions to improve it.
Top comments (0)