路由 - abowloflrf/notesrepo GitHub Wiki

路由总览

+--------+----------+--------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                      | Name             | Action                                                                 | Middleware   |
+--------+----------+--------------------------+------------------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                        | home             | App\Http\Controllers\HomeController@index                              | web,auth:web |
|        | POST     | api/auth/login           |                  | App\Http\Controllers\AuthController@login                              | api          |
|        | POST     | api/auth/logout          |                  | App\Http\Controllers\AuthController@logout                             | api,auth:api |
|        | POST     | api/auth/me              |                  | App\Http\Controllers\AuthController@me                                 | api,auth:api |
|        | POST     | api/auth/refresh         |                  | App\Http\Controllers\AuthController@refresh                            | api,auth:api |
|        | DELETE   | api/folder/empty         |                  | App\Http\Controllers\FolderController@emptyFolder                      | api,auth:api |
|        | POST     | api/folder/new           |                  | App\Http\Controllers\FolderController@createFolder                     | api,auth:api |
|        | POST     | api/folder/rename        |                  | App\Http\Controllers\FolderController@renameFolder                     | api,auth:api |
|        | GET|HEAD | api/notes                |                  | App\Http\Controllers\NotesController@getNotesList                      | api,auth:api |
|        | POST     | api/notes/new            |                  | App\Http\Controllers\NotesController@createNote                        | api,auth:api |
|        | POST     | api/notes/publish/{uuid} |                  | App\Http\Controllers\NotesController@changePublicStatus                | api,auth:api |
|        | GET|HEAD | api/notes/{uuid}         |                  | App\Http\Controllers\NotesController@getSingleNote                     | api,auth:api |
|        | POST     | api/notes/{uuid}         |                  | App\Http\Controllers\NotesController@updateSingleNote                  | api,auth:api |
|        | DELETE   | api/notes/{uuid}         |                  | App\Http\Controllers\NotesController@deleteSingleNote                  | api,auth:api |
|        | GET|HEAD | api/todo                 |                  | App\Http\Controllers\TodosController@get                               | api,auth:api |
|        | POST     | api/todo                 |                  | App\Http\Controllers\TodosController@update                            | api,auth:api |
|        | GET|HEAD | login                    | login            | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                    |                  | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                   | logout           | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | GET|HEAD | p/{uuid}                 |                  | App\Http\Controllers\PublicController@index                            | web          |
|        | GET|HEAD | register                 | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register                 |                  | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
|        | GET|HEAD | workspace                | workspace        | App\Http\Controllers\WorkspaceController@index                         | web,auth:web |
+--------+----------+--------------------------+------------------+------------------------------------------------------------------------+--------------+

web.php

Laravel Web 路由

Auth::routes();//默认的认证路由,只使用了注册与登陆功能
Route::get('/', 'HomeController@index')->name('home');
Route::get('/workspace','WorkspaceController@index')->name('workspace');//web中间件,使用Cookie Session认证来认证进入笔记工作台
Route::get('/p/{uuid}','PublicController@index');//用户发布的笔记,将单篇笔记发表为所有人可以查看的静态站点

api.php

关键 Laravel api 路由,在/workspace 这个单页网站上使用的 api

认证相关

Route::group(['middleware' => 'api', 'prefix' => 'auth'], function ($router) {
Route::post('login', 'AuthController@login');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');
});

笔记操作相关 api

Route::group(['middleware' => 'api', 'prefix' => 'notes'], function ($router) {
Route::get('', 'NotesController@getNotesList');
Route::post('new', 'NotesController@createNote');
Route::get('{uuid}', 'NotesController@getSingleNote');
Route::post('{uuid}', 'NotesController@updateSingleNote');
Route::delete('{uuid}', 'NotesController@deleteSingleNote');
Route::post('publish/{uuid}','NotesController@changePublicStatus');
});

文件夹操作相关 api

Route::group(['middleware' => 'api', 'prefix' => 'folder'], function ($router) {
Route::post('new', 'FolderController@createFolder');
Route::delete('empty', 'FolderController@emptyFolder');
Route::post('rename', 'FolderController@renameFolder');
});

TODO 操作相关 api

Route::group(['prefix' => 'api','prefix'=>'todo'], function ($router) {
Route::get('','TodosController@get');
Route::post('','TodosController@update');
});