warrior-code-api
Version:
API for Warrior-Code.
170 lines (145 loc) • 2.92 kB
JavaScript
const Joi = require('joi');
module.exports = [
// Index.
{
path: '/',
method: 'GET',
config: {
handler: require('./controllers/index')
}
},
// Login.
{
path: '/login',
method: ['GET', 'POST'],
config: {
auth: 'github',
handler: require('./controllers/login')
}
},
{
path: '/test-token',
method: 'GET',
config: {
auth: 'token',
handler: (request, reply) => {
reply('ok');
}
}
},
// Campaigns.
{
path: '/campaigns',
method: 'GET',
config: {
auth: 'token',
handler: require('./controllers/campaigns').index
}
},
{
path: '/campaigns',
method: 'POST',
config: {
auth: 'token',
handler: require('./controllers/campaigns').create,
validate: {
payload: Joi.object().keys({
name: Joi.string(),
world: Joi.string().required(),
isWaitingForPlayers: Joi.boolean() // If playing solo set this var to `false`.
})
}
}
},
{
path: '/campaigns/{id}',
method: 'GET',
config: {
auth: 'token',
handler: require('./controllers/campaigns').show
}
},
// {
// path: '/campaigns/{id}',
// method: 'PUT',
// config: {
// auth: 'token',
// handler: require('./controllers/campaigns').update
// }
// },
{
path: '/campaigns/{id}/add-player',
method: 'POST',
config: {
auth: 'token',
handler: require('./controllers/campaigns').addPlayer,
validate: {
payload: Joi.object().length(1).keys({
player: Joi.string().regex(/[a-zA-Z0-9]{16}/).required()
})
}
}
},
// Codes.
{
path: '/codes',
method: 'GET',
config: {
auth: 'token',
handler: require('./controllers/codes').index
}
},
{
path: '/codes',
method: 'POST',
config: {
auth: 'token',
handler: require('./controllers/codes').create,
validate: {
payload: Joi.object().length(2).keys({
campaign: Joi.string().regex(/[a-zA-Z0-9]{16}/).required(),
script: Joi.string().required()
})
}
}
},
{
path: '/codes/{id}',
method: 'GET',
config: {
auth: 'token',
handler: require('./controllers/codes').show
}
},
// {
// path: '/codes/{id}',
// method: 'PUT',
// config: {
// auth: 'token',
// handler: require('./controllers/codes').update
// }
// }
// Maps.
{
path: '/maps',
method: 'GET',
config: {
handler: require('./controllers/maps').index
}
},
// Worlds.
{
path: '/worlds',
method: 'GET',
config: {
handler: require('./controllers/worlds').index
}
},
{
path: '/worlds/{name}',
method: 'GET',
config: {
handler: require('./controllers/worlds').show
}
}
];