ahserver is a http(s) server base on aiohttp asynchronous framework.
ahserver capabilities:
* user authorization and authentication support
* https support
* processor for registed file type
* pre-defined variables and function can be called by processors
* multiple database connection and connection pool
* a easy way to wrap SQL
* configure data from json file stored at ./conf/config.json
* upload file auto save under config.filesroot folder
* i18n support
* processors include:
+ 'dspy' file subffix by '.dspy', is process as a python script
+ 'tmpl' files subffix by '.tmpl', is process as a template
+ 'md' files subffix by '.md', is process as a markdown file
+ 'xlsxds' files subffix by '.xlsxds' is process as a data source from xlsx file
+ 'sqlds' files subffixed by '.sqlds' is process as a data source from database via a sql command
## Requirements
see requirements.txt
[pyutils](https://github.com/yumoqing/pyutils)
[sqlor](https://github.com/yumoqing/sqlor)
## How to use
see ah.py
```
from ahserver.configuredServer import ConfiguredServer
if __name__ == '__main__':
server = ConfiguredServer()
server.run()
```
## Folder structure
+ app
+ |-ah.py
+ |--ahserver
+ |-conf
+ |-config.json
+ |-i18n
## Configuration file content
ahserver using json file format in its configuration, the following is a sample:
```
{
"debug":true,
"databases":{
"aiocfae":{
"driver":"aiomysql",
"async_mode":true,
"coding":"utf8",
"dbname":"cfae",
"kwargs":{
"user":"test",
"db":"cfae",
"password":"test123",
"host":"localhost"
}
},
"cfae":{
"driver":"mysql.connector",
"coding":"utf8",
"dbname":"cfae",
"kwargs":{
"user":"test",
"db":"cfae",
"password":"test123",
"host":"localhost"
}
}
},
"website":{
"paths":[
"/path/to/path1",
"/path/to/path2",
"/path/to/path3",
"/path/to/path4"
],
"host":"0.0.0.0",
"port":8080,
"coding":"utf-8",
"indexes":[
"index.html",
"index.tmpl",
"index.dspy",
"index.md"
],
"visualcoding":{
"default_root":"/vc/test",
"userroot":{
"ymq":"/vc/ymq",
"root":"/vc/root"
},
"jrjpath":"/vc/default"
},
"processors":[
[".xlsxds","xlsxds"],
[".sqlds","sqlds"],
[".tmpl.js","tmpl"],
[".tmpl.css","tmpl"],
[".html.tmpl","tmpl"],
[".tmpl","tmpl"],
[".dspy","dspy"],
[".md","md"]
]
},
"langMapping":{
"zh-Hans-CN":"zh-cn",
"zh-CN":"zh-cn",
"en-us":"en",
"en-US":"en"
}
}
```
### run mode configuration
if want viboraserver running in debug mode, just add a key-value pairs in config.json
```
"debug":true,
```
else just delete this key-value in config.json in conf folder
### database configuration
viboraserver support database data operations, corrently, it ***ONLY*** support synchronous DBAPI2.
the viboraserver using packages for database engines are:
* oracle:cx_Oracle
* mysql:mysql-connector
* postgresql:psycopg2
* sql server:pymssql
however, you can change it, but must change the "driver" value the the package name in the database connection definition.
in the databases section in config.json, you can define one or more database connection, and also, it support many database engine, just as ORACLE,mysql,postgreSQL.
define a database connnect you need follow the following json format.
* mysql or mariadb
```
"metadb":{
"driver":"mysql.connector",
"coding":"utf8",
"dbname":"sampledb",
"kwargs":{
"user":"user1",
"db":"sampledb",
"password":"user123",
"host":"localhost"
}
}
```
the dbname and "db" should the same, which is the database name in mysql database
* Oracle
```
"db_ora":{
"driver":"cx_Oracle",
"coding":"utf8",
"dbname":sampledb",
"kwargs":{
"user":"user1",
"host":"localhost",
"dsn":"10.0.185.137:1521/SAMPLEDB"
}
}
```
* SQL Server
```
"db_mssql":{
"driver":"pymssql",
"coding":"utf8",
"dbname":"sampledb",
"kwargs":{
"user":"user1",
"database":"sampledb",
"password":"user123",
"server":"localhost",
"port":1433,
"charset":"utf8"
}
}
```
* PostgreSQL
```
"db_pg":{
"driver":"psycopg2",
"dbname":"testdb",
"coding":"utf8",
"kwargs":{
"database":"testdb",
"user":"postgres",
"password":"pass123",
"host":"127.0.0.1",
"port":"5432"
}
}
```
### website configuration
#### paths
viboraserver can serve its contents (static file, dynamic contents render by its processors) resided on difference folders in the server file system.
viboraserver finds a content identified by http url in order the of the paths specified by "paths" lists inside "website" definition of config.json file
#### processors
all the prcessors viboraserver using, must be listed here.
#### host
by defaualt, '0.0.0.0'
#### port
by default, 8080
#### coding
viboraserver recomments using 'utf-8'
#### indexes
default content file names, viboraserver will use first found file names in the folder
### langMapping
the browsers will send 'Accept-Language' are difference even if the same language. so viboraserver using a "langMapping" definition to mapping multiple browser lang to same i18n file
## international
viboraserver using MiniI18N in appPublic modules in pyutils package to implements i18n support
it will search translate text in ms* txt file in folder named by language name inside i18n folder in workdir folder, workdir is the folder where the viboraserver program resided or identified by command line paraments.
## performance
You can find "Hello world" performance about viboraserver in [vibora](https://github.com/vibora-io/vibora) main page
viboraserver will list and performance test for its processors later
### test macheine
xiaomi pro 15.6 i7 cpu, 16Gb memory,m2 256G disk
os: ubuntu 18.4
vibora 0.0.7
### static file
```
Running 30s test @ http://localhost:8080/swift/books/hub/welcome.htm