1.2.2 • Published 3 years ago

wss-autoload v1.2.2

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

wss-autoload

install

npm i wss-autoload

options

  • dir:
  • options:If you want to pass some custom options to the registered plugins via fastify-autoload, use the options key
  • ignorePattern:If you have some files in the folder that you'd like autoload to skip you can set ignorePattern option to a regex. If that matches a file it will not load it.
  • includeTypeScript:If you are using TypeScript and something like ts-node to load the .ts files directly you can set includeTypeScript option to true. This will load plugins from .ts files as well as .js files.

usage

import { join } from 'path';
import { createServer } from 'http';
import { Server } from 'wssio';
import { namespaceAutoload } from 'wss-autoload';
import { namespacePlugin } from 'wss-plugin';
const server = createServer();
const wssio = new Server({
  server,
});
const nsp = wssio.of('/test');
// 注册关闭钩子函数、以达到关闭服务
nsp.register(namespacePlugin((namespace, _opts, done) => {
  namespace.addHook('onClose', () => {
    wssio.close();
    server.close();
  });
  done();
}, {
  name: 'onClose',
}));
nsp.register(namespaceAutoload, {
  dir:path.join(__dirname, 'foo')
}).ready((err)=>{
  nsp.$log.info('wss ready.....');
  nsp.$log.error(err);
  server.listen(3000, '0.0.0.0');
});
1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.0

3 years ago