API Reference

svrx(option)

Get the instance of Svrx

Usage

const svrx = require('@svrx/svrx');

const server = svrx({
  port: 8002
});

Param

Return

the instance of Svrx

server.start()

Start svrx

Usage

server.start().then(port => {
  console.log(port);
});

Return

Promise

server.close()

Usage

server.close().then(() => {
  console.log('Svrx has closed');
});

Param

Return

Promise

server.reload()

Manually refresh the browser

Usage

server.reload();

server.on

Attach event listener

builtin events

1. ready

Emit when svrx start

server.on('ready', port => {});

2. plugin

Emit after plugin building, as same as hook.onCreate, see How to create plugin for more details

server.on('plugin', async ({io, events, config, router, injector, logger, middleware }=>{
    // you logic here
}))

3. file:change

emit after file change (make sure that livereload is enable)

server.off

unbind specific event

server.on('file:change', handler);
server.off('file:change', handler);

server.emit

server.emit('custom-event', { param1: 1 });
Copyright © 2019, NetEase, Inc. all right reserved,powered by GitbookFile Modify: 2019-12-18 15:48:24

results matching ""

    No results matching ""