Using Tushan in Laf
Laf
is a cloud development platform that integrates functions, databases, and storage.
We can quickly implement the backend management page for the Laf
database using the preset libraries in Tushan
, with only a simple configuration of the field list required to achieve rapid implementation of the backend management system.
How to Use
Start from the Function Market
You can quickly start from the Laf function market. After clicking "Use Template", you can quickly join your application.
For the security of your database, please fill in a password and key with high randomness to prevent cracking.
Manual Addition
Create an interceptor in your Laf application (named: __interceptor__
).
Install the dependency tushan-laf-json-server
, taking the latest version.
Start with the following content:
import { createTushanJsonServerInterceptor } from 'tushan-laf-json-server'
export default async function (ctx: FunctionContext) {
try {
return await createTushanJsonServerInterceptor(ctx as any, {
auth: {
/**
* Please modify the following three fields, which are the username, password, and secret key signature fields of the backend.
*/
username: 'tushan',
password: "tushan",
secret: "tushan-secret"
},
config: {
/**
* The following are the names and types of the database models and corresponding fields.
* Types include: text, number, avatar, json, boolean, datetime, password, select, reference, textarea, email, image, url
*
* action indicates whether to enable the corresponding function. By default, only the list page is available.
*/
resources: [
{
name: "test",
fields: [
{
name: "id",
type: "text"
},
{
name: "content",
type: "textarea",
}
],
action: {
create: true,
detail: true,
edit: true,
delete: true
}
}
]
}
});
} catch (err) {
console.error(err)
} finally {
return true;
}
}
Configuration Explanation
In createTushanJsonServerInterceptor
, two parameters are required: the http request context ctx
and the configuration options required by tushan
.
We mainly explain the configuration:
header
: Titlefooter
: Footerauth
: Authentication-relatedusername
: Backend usernamepassword
: Backend passwordsecret
: Secret key used to generate tokens, a random string is sufficient
resources
: An array for describing configured resourcesname
: Model name, corresponding to the Laf dataset namelabel
: Display name, optionalfields
: Model fields, an arrayname
: Field nametype
: Field type, internally supports text, number, avatar, json, boolean, datetime, password, select, reference, textarea, email, image, urloptions
: Field configuration, optional, refer to the usage oftushan
field configuration
filter
: Filter options, configured the same asfields
action
: Enabled functionscreate
: Createdetail
: Detailedit
: Editdelete
: Delete
authProvider
: Optional, if you want to implement your own login authentication logic, you can override itdataProvider
: Optional, if you want to implement your own resource acquisition logic, you can override it
Accessing the Backend
After deployment, access https://tushan-lite.msgbyte.com/?config=https://<appid>.laf.dev/tushan
, replacing <appid>
with the appid
of your own Laf
application.