Skip to content

Instantly share code, notes, and snippets.

@seldo
Last active August 29, 2015 13:56
Show Gist options
  • Save seldo/9124076 to your computer and use it in GitHub Desktop.
Save seldo/9124076 to your computer and use it in GitHub Desktop.
// Validation for parameters
var downloadsSchema = {
// valid periods: 2014-02-01, 2014-01-02:2014-01-04, all-time, last-day, last-week
period: Joi.string().regex(/(\d{4}-\d{2}-\d{2}(:\d{4}-\d{2}-\d{2})?|[\w-]+)/).required(),
// valid package names: jquery, jquery-express, socket.io, socket.io-express
package: Joi.string().regex(/(^[a-zA-Z0-9]([^\/\(\)&\?#\|<>@:%\s\\\*'"!~`])*)*/).optional()
};
// Add the routes
server.route({
method: 'GET',
path: '/downloads/point/{period}/{package?}',
config: {
handler: downloads.point,
validate: {
path: downloadsSchema
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment