mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-24 08:40:26 +01:00
initital commit
This commit is contained in:
46
start/kernel.ts
Normal file
46
start/kernel.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is used to define middleware for HTTP requests. You can register
|
||||
| middleware as a `closure` or an IoC container binding. The bindings are
|
||||
| preferred, since they keep this file clean.
|
||||
|
|
||||
*/
|
||||
|
||||
import Server from '@ioc:Adonis/Core/Server'
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| An array of global middleware, that will be executed in the order they
|
||||
| are defined for all HTTP requests.
|
||||
|
|
||||
*/
|
||||
Server.middleware.register([
|
||||
'Adonis/Core/BodyParserMiddleware',
|
||||
'App/Middleware/SilentAuth',
|
||||
])
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Named middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Named middleware are defined a key-value pair. The value is the namespace
|
||||
| or middleware function and key is the alias. Later you can use these
|
||||
| alias on individual routes. For example:
|
||||
|
|
||||
| { auth: 'App/Auth/Middleware' }
|
||||
|
|
||||
| and then use it as follows
|
||||
|
|
||||
| Route.get('dashboard', 'UserController.dashboard').middleware('auth')
|
||||
|
|
||||
*/
|
||||
Server.middleware.registerNamed({
|
||||
auth: 'App/Middleware/Auth',
|
||||
})
|
||||
32
start/routes.ts
Normal file
32
start/routes.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import Route from '@ioc:Adonis/Core/Route'
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
|
||||
Route.resource('users', 'UsersController').only(['index', 'show'])
|
||||
Route.get('/posts/:slug', 'PostsController.getLikes')
|
||||
Route.get('/posts/is/:slug', 'PostsController.isLiked')
|
||||
Route.post('/posts/:slug/like', 'PostsController.like')
|
||||
Route.post('/posts/:slug/unlike', 'PostsController.unlike')
|
||||
Route.resource('subscribers', 'SubscribersController').only(['index', 'show'])
|
||||
Route.resource('files', 'FileController').only(['index'])
|
||||
|
||||
Route.get('/files/:filename', async ({ response, params }) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
})
|
||||
|
||||
Route.group(() => {
|
||||
Route.resource('users', 'UsersController').only(['store', 'update', 'destroy'])
|
||||
Route.resource('posts', 'PostsController').only(['store', 'update', 'destroy'])
|
||||
Route.resource('subscribers', 'SubscribersController').only(['store', 'update', 'destroy'])
|
||||
Route.resource('files', 'FileController').only(['store', 'update', 'destroy'])
|
||||
|
||||
}).middleware('auth')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/me', 'AuthController.user').middleware('auth')
|
||||
|
||||
Route.post('/web/login', 'AuthController.loginWeb')
|
||||
Route.post('/web/logout', 'AuthController.logoutWeb')
|
||||
|
||||
Route.post('/api/login', 'AuthController.loginApi')
|
||||
Route.post('/api/logout', 'AuthController.logoutApi')
|
||||
}).prefix('auth')
|
||||
Reference in New Issue
Block a user