mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
57
start/bouncer.ts
Normal file
57
start/bouncer.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Contract source: https://git.io/Jte3T
|
||||
*
|
||||
* Feel free to let us know via PR, if you find something broken in this config
|
||||
* file.
|
||||
*/
|
||||
|
||||
import Bouncer from '@ioc:Adonis/Addons/Bouncer'
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bouncer Actions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Actions allows you to separate your application business logic from the
|
||||
| authorization logic. Feel free to make use of policies when you find
|
||||
| yourself creating too many actions
|
||||
|
|
||||
| You can define an action using the `.define` method on the Bouncer object
|
||||
| as shown in the following example
|
||||
|
|
||||
| ```
|
||||
| Bouncer.define('deletePost', (user: User, post: Post) => {
|
||||
| return post.user_id === user.id
|
||||
| })
|
||||
| ```
|
||||
|
|
||||
|****************************************************************
|
||||
| NOTE: Always export the "actions" const from this file
|
||||
|****************************************************************
|
||||
*/
|
||||
export const {actions} = Bouncer
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bouncer Policies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Policies are self contained actions for a given resource. For example: You
|
||||
| can create a policy for a "User" resource, one policy for a "Post" resource
|
||||
| and so on.
|
||||
|
|
||||
| The "registerPolicies" accepts a unique policy name and a function to lazy
|
||||
| import the policy
|
||||
|
|
||||
| ```
|
||||
| Bouncer.registerPolicies({
|
||||
| UserPolicy: () => import('App/Policies/User'),
|
||||
| PostPolicy: () => import('App/Policies/Post')
|
||||
| })
|
||||
| ```
|
||||
|
|
||||
|****************************************************************
|
||||
| NOTE: Always export the "policies" const from this file
|
||||
|****************************************************************
|
||||
*/
|
||||
export const {policies} = Bouncer.registerPolicies({})
|
||||
@@ -1,95 +0,0 @@
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import HealthCheck from "@ioc:Adonis/Core/HealthCheck";
|
||||
import Env from '@ioc:Adonis/Core/Env'
|
||||
|
||||
const BASE_URL = Env.get('BASE_URL')
|
||||
|
||||
Route.get('/', async ({response}: HttpContextContract) => {
|
||||
return response.status(200).send({
|
||||
domain: BASE_URL,
|
||||
version: Env.get('API_VERSION'),
|
||||
source: `${BASE_URL}/source`,
|
||||
healthCheck: `${BASE_URL}/health`,
|
||||
routes: {
|
||||
profile: `${BASE_URL}/profile`,
|
||||
//stats: `${BASE_URL}/stats`,
|
||||
states: `${BASE_URL}/states`,
|
||||
locations: `${BASE_URL}/locations`,
|
||||
projects: `${BASE_URL}/projects`
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Route.get('/source', async ({response}: HttpContextContract) => {
|
||||
return response.redirect(Env.get('GITHUB_SOURCE'))
|
||||
})
|
||||
|
||||
Route.get('/health', async ({response}: HttpContextContract) => {
|
||||
const report = await HealthCheck.getReport()
|
||||
const isLive = await HealthCheck.isLive()
|
||||
const isReady = await HealthCheck.isReady()
|
||||
return report.healthy ? response.ok({ isLive, isReady, report: report.report }) : response.badRequest({ isLive, isReady, report: report.report })
|
||||
})
|
||||
|
||||
// ArtAPI
|
||||
Route.get('/profile', 'ProfileController.me')
|
||||
Route.get('/locations', 'LocationsController.get')
|
||||
Route.get('/stats', 'StatsController.get')
|
||||
Route.get('/states', 'StatesController.get')
|
||||
Route.get('/projects', 'ProjectsController.get')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/discord', 'ProfileController.discord')
|
||||
Route.post('/form', 'FormsController.send')
|
||||
Route.post('/states/:state', 'StatesController.set')
|
||||
|
||||
Route.resource('/users', 'UsersController')
|
||||
Route.resource('/files', 'FileController').only(['store', 'destroy'])
|
||||
|
||||
Route.post('/locations', 'LocationsController.store')
|
||||
Route.post('/projects', 'ProjectsController.store')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/:slug', 'PostsController.getLikes')
|
||||
Route.post('/:slug/like', 'PostsController.like')
|
||||
Route.post('/:slug/unlike', 'PostsController.unlike')
|
||||
}).prefix('/posts')
|
||||
|
||||
Route.get('/subscribers', 'SubscribersController.get')
|
||||
Route.post('/subscribers', 'SubscribersController.store')
|
||||
|
||||
Route.get('/guestbook', 'GuestBookController.get')
|
||||
Route.post('/guestbook', 'GuestBookController.store')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/', 'FileController.index')
|
||||
Route.get('/:filename', async ({response, params}) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
})
|
||||
}).prefix('/files')
|
||||
|
||||
}).middleware('auth')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/me', 'AuthController.user').middleware('auth')
|
||||
Route.post('/token', 'AuthController.createInfiniteToken')
|
||||
|
||||
Route.post('/login', 'AuthController.login')
|
||||
Route.post('/logout', 'AuthController.logout')
|
||||
|
||||
Route.get('/twitter/callback', 'AuthController.twitter')
|
||||
Route.get('/github/callback', 'AuthController.github')
|
||||
Route.get('/google/callback', 'AuthController.google')
|
||||
|
||||
Route.get('/twitter', async ({ally}) => {
|
||||
return ally.use('twitter').redirect()
|
||||
})
|
||||
Route.get('/github', async ({ally}) => {
|
||||
return ally.use('github').redirect()
|
||||
})
|
||||
Route.get('/google', async ({ally}) => {
|
||||
return ally.use('google').redirect()
|
||||
})
|
||||
}).prefix('/auth')
|
||||
17
start/routes/artapi.ts
Normal file
17
start/routes/artapi.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/discord', 'ProfileController.discord')
|
||||
Route.post('/states/:state', 'StatesController.set')
|
||||
Route.resource('/users', 'UsersController')
|
||||
Route.post('/locations', 'LocationsController.store')
|
||||
Route.post('/projects', 'ProjectsController.store')
|
||||
Route.resource('/files', 'FileController').only(['store', 'destroy'])
|
||||
Route.group(() => {
|
||||
Route.get('/', 'FileController.index')
|
||||
Route.get('/:filename', async ({response, params}) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
})
|
||||
}).prefix('/files')
|
||||
}).middleware('auth')
|
||||
15
start/routes/artsite.ts
Normal file
15
start/routes/artsite.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
|
||||
Route.group(() => {
|
||||
Route.post('/form', 'FormsController.send')
|
||||
Route.group(() => {
|
||||
Route.get('/:slug', 'PostsController.getLikes')
|
||||
Route.post('/:slug/like', 'PostsController.like')
|
||||
Route.post('/:slug/unlike', 'PostsController.unlike')
|
||||
}).prefix('/posts')
|
||||
Route.get('/subscribers', 'SubscribersController.get')
|
||||
Route.post('/subscribers', 'SubscribersController.store')
|
||||
Route.delete('/subscribers', 'SubscribersController.delete')
|
||||
Route.get('/guestbook', 'GuestBookController.get')
|
||||
Route.post('/guestbook', 'GuestBookController.store')
|
||||
}).middleware('auth')
|
||||
23
start/routes/auth.ts
Normal file
23
start/routes/auth.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/me', 'AuthController.user').middleware('auth')
|
||||
Route.post('/token', 'AuthController.createInfiniteToken')
|
||||
|
||||
Route.post('/login', 'AuthController.login')
|
||||
Route.post('/logout', 'AuthController.logout')
|
||||
|
||||
Route.get('/twitter/callback', 'AuthController.twitter')
|
||||
Route.get('/github/callback', 'AuthController.github')
|
||||
Route.get('/google/callback', 'AuthController.google')
|
||||
|
||||
Route.get('/twitter', async ({ally}) => {
|
||||
return ally.use('twitter').redirect()
|
||||
})
|
||||
Route.get('/github', async ({ally}) => {
|
||||
return ally.use('github').redirect()
|
||||
})
|
||||
Route.get('/google', async ({ally}) => {
|
||||
return ally.use('google').redirect()
|
||||
})
|
||||
}).prefix('/auth')
|
||||
43
start/routes/home.ts
Normal file
43
start/routes/home.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import Env from "@ioc:Adonis/Core/Env";
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import HealthCheck from "@ioc:Adonis/Core/HealthCheck";
|
||||
|
||||
const BASE_URL = Env.get('BASE_URL')
|
||||
|
||||
Route.get('/', async ({response}: HttpContextContract) => {
|
||||
return response.status(200).send({
|
||||
domain: BASE_URL,
|
||||
version: Env.get('API_VERSION'),
|
||||
source: `${BASE_URL}/source`,
|
||||
healthCheck: `${BASE_URL}/health`,
|
||||
routes: {
|
||||
profile: `${BASE_URL}/profile`,
|
||||
//stats: `${BASE_URL}/stats`,
|
||||
states: `${BASE_URL}/states`,
|
||||
locations: `${BASE_URL}/locations`,
|
||||
projects: `${BASE_URL}/projects`
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Route.get('/source', async ({response}: HttpContextContract) => {
|
||||
return response.redirect(Env.get('GITHUB_SOURCE'))
|
||||
})
|
||||
|
||||
Route.get('/health', async ({response}: HttpContextContract) => {
|
||||
const report = await HealthCheck.getReport()
|
||||
const isLive = await HealthCheck.isLive()
|
||||
const isReady = await HealthCheck.isReady()
|
||||
return report.healthy ? response.ok({isLive, isReady, report: report.report}) : response.badRequest({
|
||||
isLive,
|
||||
isReady,
|
||||
report: report.report
|
||||
})
|
||||
})
|
||||
|
||||
Route.get('/profile', 'ProfileController.me')
|
||||
Route.get('/locations', 'LocationsController.get')
|
||||
Route.get('/stats', 'StatsController.get')
|
||||
Route.get('/states', 'StatesController.get')
|
||||
Route.get('/projects', 'ProjectsController.get')
|
||||
4
start/routes/index.ts
Normal file
4
start/routes/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import './artsite'
|
||||
import './artapi'
|
||||
import './auth'
|
||||
import './home'
|
||||
Reference in New Issue
Block a user