dictServer.js 946 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**!
  2. * cnpmjs.org - dispatch.js
  3. *
  4. * Copyright(c) cnpmjs.org and other contributors.
  5. * MIT Licensed
  6. *
  7. * Authors:
  8. * dead_horse <dead_horse@qq.com>
  9. * fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
  10. */
  11. /******************* 敏感字过滤服务,在生产环境中使用 ***************************/
  12. 'use strict';
  13. /**
  14. * Module dependencies.
  15. */
  16. var fs = require('fs');
  17. var C = require('./config');
  18. // 启动字词过滤服务器
  19. var server = require('sc-filter').createServer();
  20. if (C.wordFilter.unix_socket){ // Unix Socket 方式
  21. if(fs.existsSync(C.wordFilter.unix_socket)){
  22. fs.unlinkSync(C.wordFilter.unix_socket);
  23. }
  24. server.set('connectStr',C.wordFilter.unix_socket);
  25. }else{ // TCP 方式
  26. server.set('connectStr',C.wordFilter.port);
  27. }
  28. server.loadDict(function loaded(){
  29. server.listen(server.get('connectStr'), function(){
  30. console.log('Dict server is listening on ' + server.get('connectStr'));
  31. });
  32. });