ETMX Typescritp Server Framework
Typescript node.js 服务器开发框架
声明
本人英文不好,莫笑。
Install(安装)
npm install -g etmx
Use ETMX(使用ETMX)
etmx create [project name]
Description(描述)
ETMX is a typescript server framework, base on express framework.
ETMX contains:
1、 Server(use this class to create a server)
2、 Router(use this class to create a router)
3、 RouterManager(use this class to manage routers)
4、 Database(use this class to handle database)
Configurations(配置)
ETMX use a .json file or a object like to configure server, configurations contains:
-
server ------ server base configurations
-
port ------ port of web server listen, default is 3000
-
protocol ------ http or https, default is http
-
https ------ if https protocol used, configure this field
-
cert ------ ssl cert
-
key ------ private key of cert
-
-
path ------ this configurations contains used paths of server
-
cache ------ path of cache directory, default is /temp/etmx
-
static ------ path of static resources directory(s),
-
view ------ path of view, if you don't hav views, ignore it
-
cross ------ is cross-domain, default is false
-
favicon ------ path of favicon image
-
websocket ------ use web socket, default is false
-
log ------ is request log show, default is true
-
-
database ------ database configurations
-
type ------ database type, default is mysql, but now, only mysql can be used
-
host ------ database host, default is localhost
-
port ------ database port, this will use default port of database that you set
-
user ------ database user
-
password ------ password of database user
-
db ------ database to use
-
charset ------ charset of mysql to use, default is utf8
-
timezone ------ timezone of mysql to use, default is local
-
Create Route(创建路由)
use Router class to create a router, example:
; ; router //set router name .name'/main' //hello world .get'/test', //mysql query .get'/user/:number/:name',;//must use export default to export a router;
Create server(创建服务器)
Now, let's create a server and start it
;; //set path of server configurationsServer.confdir = path.join__dirname, './';//set server root file directoryServer.rootdir = __dirname; //create a server use etmx.json file; //set routersserver.routers = ; //use create method to create a serverserver.create;
How to use websocket (websocket使用)
Etmx provide a easy way to create and manage websocket, to use websocket you should do:
- open serverconfig set websocket field a true value
- create a websocet handler
- open your webserver entry file and add websocket handler
:::notice:if your webserver use https websocket is wss://, if http websocket is ws://
webscket setting like:
websocket handler like:
; //this is websocket params
the end, in entry file set
server.wsHandler = HandlerName;