Created
November 30, 2014 21:24
-
-
Save ciwolsey/189c7168e85185fdadc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Schemas = {}; | |
| Schemas.HostLogs = new SimpleSchema({ | |
| ip: { | |
| type: String, | |
| label: "IP", | |
| custom: function(){ | |
| if(this.isFromTrustedCode){ | |
| // trusted, no need for regex validation | |
| } else { | |
| var value = this.value; | |
| var ip = SimpleSchema.RegEx.IP; | |
| var domain = SimpleSchema.RegEx.Domain; | |
| if(!(ip.test(value) || domain.test(value))){ | |
| return "Hostname must be either an IP or domain" | |
| } | |
| } | |
| } | |
| }, | |
| port: { | |
| type: Number, | |
| label: "Port", | |
| min: 1, | |
| max: 65535, | |
| }, | |
| status: { | |
| type: String, | |
| optional: true, | |
| } | |
| }); | |
| HostLogs = new Mongo.Collection('hostlogs'); | |
| HostLogs.attachSchema(Schemas.HostLogs); | |
| var hostLogsContext = Schemas.HostLogs.namedContext('default'); | |
| // Enabling unique indexing of ip/port | |
| if(Meteor.isServer){ | |
| HostLogs._ensureIndex({ip:1, port:1}, {unique: 1}); | |
| } | |
zimme
commented
Dec 1, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment