Heze is a light Swift server-side framework powered by Perfect 3.x.
Heze recommends MySQL 5.7.
- Make sure you have
mysql server 5.7installed on your Mac. - Clone this repo.
- Fill
usernameandpasswordfield in config file atWorkspace/HezeDemo/config.json. - Run
swift package generate-xcodeprojto generate the Xcode project. - Edit path params in
main.swiftatHezeDemo. - RUN. Go to
http://localhost:8080to see how the demo looks.
- API: Use
HezeHandlerto process request and return a JSON object by usingHezeResponsemethod. - Web: Use
HezeVieworHezeListView. HTML rendering usesMustachetech which is powered by Perfect-Mustache
Routes need to be registered in AppDelegate. See the demo.
- Request filter: Use
HezeRequestFilter. OverriderequestFiltermethod to decide if the request can pass the filter. - Response filter: Use
HezeResponseFilter. - Session:
HezeSessionRequestFilteris a request filter to process session. Tokens are stored in MySQL by default.
Filter need to be registered in AppDelegate as a plugin.
Use HezeTimer.
Timer need to be registered in AppDelegate as a plugin.
Workspace contains:
config.json: Configration.Public: Static resources.Views: Web templates.
Context system allows you to create multiple servers in one target.
Every AppDelegate requires a context. HezeApp will storage some env vars in this context when it inits.
There are main context and meta context by default. You can create more context. See HezeContextBox.
DO NOT TOUCH META CONTEXT.
Heze supports email.
Adding these config in config.json will enable the email client.
"mail": {
"smtp": "smtp://xxx",
"username": "noreply@xxx",
"password": "",
"name": "xxx-NoReply",
"interval": 3.0,
}It's powered by PerfectSMTP.
Look at class HezeDatabase. It's a abstract interface of database. Feel free to implement HezeDatabaseImpl yourself.
You may need to process Session yourself because HezeSessionRequestFilter is powered by PerfectSessionMySQL.
My website https://blog.yuusann.com is powered by Heze and SPiCa.
SPiCa is another framework which is used to create Vue app using Swift. Not opensource yet.
Feel free to contact me: i@yuusann.com