util.js 982 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var util = {
  2. debug: false,
  3. inherits: function(ctor, superCtor) {
  4. ctor.super_ = superCtor;
  5. ctor.prototype = Object.create(superCtor.prototype, {
  6. constructor: {
  7. value: ctor,
  8. enumerable: false,
  9. writable: true,
  10. configurable: true
  11. }
  12. });
  13. },
  14. extend: function(dest, source) {
  15. source = source || {};
  16. for(var key in source) {
  17. if(source.hasOwnProperty(key)) {
  18. dest[key] = source[key];
  19. }
  20. }
  21. return dest;
  22. },
  23. randomId: function () {
  24. return (Math.random().toString(36) + '0000000000000000000').substr(2, 16);
  25. },
  26. prettyError: function (msg) {
  27. console.log('ERROR PeerServer: ', msg);
  28. },
  29. allowCrossDomain: function(req, res, next) {
  30. res.setHeader('Access-Control-Allow-Origin', '*');
  31. res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  32. res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
  33. next();
  34. }
  35. };
  36. module.exports = util;