erin
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.11 • Public • Published
    框架LOGO

    Erin:基于NodeJs的微服务框架


    框架文档   |   WIKI


    快速示例

    (async () => {
        	@APIController()
        	class SubApiController extends Controller {
        		@Action()
        		public async subIndex() {
        			return 'This is sub-index'
        		}
        	}
        
        	@APIController({indexAction: 'api-index'})
        	class ApiRootController extends Controller {
        		@Action({method: 'ALL'})
        		public async apiIndex(req, res, actionParams) {
        			return 'This is api index'
        		}
        
        		@Action({
        			method: 'POST', acceptParam: false, schema: {
        				query: {
        					name: String.required(),
        					age: Number.required()
        				}, body: {
        					baby: Boolean.required()
        				}
        			}
        		})
        		public async apiSchema(req, res, actionParams) {
        			console.log(actionParams)
        
        		}
        
        		@Upload()
        		public async apiUpload(req, res, files) {
        			console.log(files)
        			return 'Upload success'
        		}
        
        		@Download()
        		public async apiDownload(req, res, callbackFn) {
        			callbackFn((err) => {
        				if (err) {
        					console.error(err)
        				} else {
        					console.log('File download done')
        				}
        			})
        			return './test/files/test.jpeg'
        		}
        
        		@SubController({acceptParam: false})
        		public async subApiController() {
        			/**
        			 * Access sub api controller
        			 */
        			return SubApiController
        		}
        	}
        
        	class Tester {
        		public num: number;
        
        		constructor(config: { num: number }) {
        			this.num = config.num
        		}
        
        		public getNum(): number {
        			return this.num
        		}
        	}
        
        	class TestComponent extends Component<Tester> {
        		public coreClass(): Constructor<Tester> {
        			return Tester
        		}
        
        		protected beforeMount(): void {
        			console.log('before mount')
        		}
        
        		protected afterMount(): void {
        			console.log('after mount')
        		}
        
        		public async initialize(core: Tester): Promise<Tester> {
        			return core
        		}
        	}
        
        	await createApplication({
        		name: '应用程序名称',
        		bootstrap: {
        			components: {
        				tester: {
        					class: TestComponent,
        					config: {num: 1024}
        				}
        			},
        			params: {
        				author: 'Handsome boy',
        				age: 'I do not tell you'
        			},
        			path: {
        				yourHeart: '/usr/secret/heart'
        			},
        			database: {
        				type: 'mysql',
        				host: 'localhost',
        				port: 3306,
        				username: 'root',
        				password: '123456',
        				database: 'erin_example_db',
        				entities: [
        					`${path.resolve(__dirname, '../')}/entities/**/*`
        				],
        				synchronize: true
        			},
        			api: {
        				port: 8080,
        				hostname: '0.0.0.0',
        				rootController: ApiRootController
        			},
        			rpc: {
        				RpcServices: [],
        				token: 'erin-token',
        				master: true
        			}
        		}
        	})
        
        	//Application launched
        	console.log(Application.Components.tester.getNum() === 1024)
        })()
    

    使用Erin-Helper快速部署Erin框架

    安装Erin-Helper:
    npm install -g erin-helper
    
    在需要部署的项目目录下执行:
    erin-helper
    

    联系方式

    • Email:Alex.Ma@thinkraz.com
    • Wechat:MYQ-1991
    * 联系请注明来意
    Powered by Thinkraz Inc.

    Install

    npm i erin

    DownloadsWeekly Downloads

    25

    Version

    1.2.11

    License

    MIT

    Unpacked Size

    597 kB

    Total Files

    395

    Last publish

    Collaborators

    • avatar