@@ -40,71 +40,78 @@ over and over on the backend. If your application needs one or all of
40
40
user management, database, file storage, real-time interactions, it should be
41
41
a good fit.
42
42
43
- I'm personally using it to build SaaS.
43
+ I'm personally using it to build SaaS:
44
44
45
- ## How it works / dev workflow
46
-
47
- The main idea is that StaticBackend is your backend API for your frontend apps.
48
-
49
- It needs to have access to MongoDB and Redis servers. Once you have your instance
50
- running you create accounts for your applications.
45
+ * [ Tangara - one page checkout for creators] ( https://tangara.io )
51
46
52
- An account has its own database, file storage, etc.
53
-
54
- I think ` app ` might have been a better name instead of ` account ` . Naming things
55
- is hard.
47
+ ## How it works / dev workflow
56
48
57
- A StaticBackend account(app) can have multiple user accounts and each user
58
- accounts may have multiple users .
49
+ The main idea is that StaticBackend is your backend API for your frontend apps.
50
+ A performant free and open-source Firebase alternative .
59
51
60
- From there each users can create database documents that are by default Read/Write
61
- for the owner (the user) and Read for its parent account. You may customize
62
- permission for each of your collection (see that later in the documentation).
52
+ _ Note that it can also be used from your backend code as well._
63
53
64
- You have the basic building blocks to create a typical web
65
- application. You have all your CRUD and data query operations covered, file
66
- storage and websocket-like capabilities.
54
+ Once you have an instance running and your first app created, you may install
55
+ the JavaScript client-side library:
67
56
68
- We have a [ JavaScript library] ( https://www.npmjs.com/package/@staticbackend/js ) to
69
- get started quickly. We have also server-side libraries for Node and Go atm.
57
+ ``` shell
58
+ $> npm install @staticbackend/js
59
+ ```
70
60
71
- Why would you need server-side libraries, was it not supposed to be a backend
72
- for client-side applications.
61
+ Let's create a user account and get a session ` token ` and create a ` task `
62
+ document in the ` tasks ` collection:
73
63
74
- Yes, but, there's always a but. Sometimes your application will need to
75
- perform tasks on behalf of users or public user that do not have access to
76
- perform CRUD from the client-side.
64
+ ``` javascript
65
+ import { Backend } from " @staticbackend/js" ;
77
66
78
- Let's imagine we're building an invoicing app. Here's the major entities
79
- we have for this examples:
67
+ const bkn = new Backend (" your_public-key" , " dev" );
80
68
81
- * A StaticBackend account (our app inside our SB instance)
82
- * An account with 2 users (this would be your customer)
83
- * An invoices collection (where your customer create invoice)
84
- * A clients collection (Your customer send invoice to their clients)
69
+ let token = " " ;
85
70
86
- Now let's imagine our customer (our app user) sends an invoice to their Client.
71
+ login = async () => {
72
+ const res = await bkn .
login (
" [email protected] " ,
" password" );
73
+ if (! res .ok ) {
74
+ console .error (res .content );
75
+ return ;
76
+ }
77
+ token = res .content ();
87
78
88
- Their client does not have any user account, but they need to see their invoice
89
- when they click on the unique link on their email they received.
79
+ createTask ();
80
+ }
90
81
91
- This can be achieve via a backend function. Couple of ways:
82
+ createTask = async () => {
83
+ const task = {
84
+ desc: " Do something for XYZ" ,
85
+ done: false
86
+ };
92
87
93
- * The email the client received can be directly a unique URL pointing to a
94
- function as a service hosted somewhere. (We will have functions soon). That
95
- function returns the invoice HTML.
96
- * Or it could be pointing to your client-side app and you perform a call to
97
- a serverless function you're hosting somewhere. That function uses the
98
- server-side library to perform a ` GET ` on behalf of the creator of the invoice
99
- document, which is our customer.
88
+ const res = bkn .create (token, " tasks" , task);
89
+ if (! res .ok ) {
90
+ console .error (res .content );
91
+ return ;
92
+ }
93
+ console .log (res .content );
94
+ }
95
+ ```
100
96
101
- The function will be able to perform a Read operation using a special ` Root Token ` .
97
+ The last ` console.log ` prints
102
98
103
- This ` Root Token ` allows your system to do anything on the server-side.
99
+ ``` json
100
+ {
101
+ "id" : " 123456-unique-id" ,
102
+ "accountId" : " aaa-bbb-unique-account-id" ,
103
+ "desc" : " Do something for XYZ" ,
104
+ "done" : false
105
+ }
106
+ ```
104
107
105
- I hope I did not lost the majority of people here ;)
108
+ From there you build your application using the
109
+ [ database] ( https://staticbackend.com/docs/database/ ) CRUD and query functions,
110
+ the [ real-time component] ( https://staticbackend.com/docs/websocket/ ) ,
111
+ the [ storage API] ( https://staticbackend.com/docs/storage/ ) , etc.
106
112
107
- This is one example of your typical day-to-day workflow using StaticBackend.
113
+ You may use server-side libraries for Node and Go or use an HTTP client
114
+ and use your preferred language.
108
115
109
116
## Get started with the self-hosted version
110
117
@@ -195,6 +202,7 @@ Here's the examples we have created so far:
195
202
196
203
* [ To-do list example] ( https://staticbackend.com/getting-started/ )
197
204
* [ Realtime collaboration] ( https://staticbackend.com/blog/realtime-collaboration-example/ )
205
+ * [ Live chat using server-side function & real-time component] ( https://staticbackend.com/blog/server-side-functions-task-scheduler-example/ )
198
206
199
207
## Deploying in production
200
208
0 commit comments