diff options
author | Ricardo <ricardo@cino.io> | 2023-10-13 14:12:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 13:12:03 +0100 |
commit | e503468660a13760010a94ecda5f0625c6f47f87 (patch) | |
tree | fa532f54fc5f091de08d55405ec6339bd2440a02 /start/routes.js | |
parent | 1.3.16 [skip ci] (diff) | |
download | ferdium-server-e503468660a13760010a94ecda5f0625c6f47f87.tar.gz ferdium-server-e503468660a13760010a94ecda5f0625c6f47f87.tar.zst ferdium-server-e503468660a13760010a94ecda5f0625c6f47f87.zip |
Server re-build with latest AdonisJS framework & Typescript (#47)
* chore: setup first basis structure
* chore: ensure styling is loaded correctly
* chore: comply to new routing syntax by replace . with / in routes/resource locations
* chore: add login controller
* chore: correctly use views with slash instead of dot
* chore: working login + tests
* chore: clean up tests
* chore: add password-forgot endpoint and matching test
* chore: add delete page test
* chore: add logout test
* chore: add reset-password route and tests
* chore: remove obsolete comment
* chore: add account-page and tests
* chore: add data page & first step of the test
* chore: add transfer/import data feature and tests
* chore: add export and basic test
* chore: add all static api routes with tests
* Regenerate 'pnpm-lock.json' and fix bad merge conflict
WIP:
- Tests have been commented out since they dont work
- Server doesn't start
* easier dev and test runs
* - remove --require-pragma from reformat-files so formatting works properly
- run pnpm reformat-files over codebase
- remove .json files from .eslintignore
- add invalid.json file to .eslintignore
- configure prettier properly in eslint config
- add type jsdoc to prettier config
- run adonis generate:manifest command to regenerate ace-manifest.json
- specify volta in package.json
- introduce typecheck npm script
- remove unused .mjs extension from npm scripts
- install missing type definition dependencies
- add pnpm.allowedDeprecatedVersions to package.json
- fix invalid extends in tsconfig.json causing TS issues throughout codebase
- remove @ts-ignore throughout codebase which is not relevant anymore
- enable some of the tsconfig options
- remove outdated eslint-disable from codebase
- change deprecated faker.company.companyName() to faker.company.name()
- fix TS issues inside transfer.spec.ts
* - update to latest node and pnpm versions
- upgrade all non-major dependencies to latest
- install missing @types/luxon dependency
- add cuid to pnpm.allowedDeprecatedVersions
- add esModuleInterop config option to tsconfig
- migrate more deprecated faker methods to new ones
- add more temporary ts-ignore to code
* - update eslint config
- remove trailingComma: all since default in prettier v3
- add typecheck command to prepare-code npm script
- upgrade various dependencies to latest major version
- update tsconfig to include only useful config options
- disable some lint issues and fix others
* - add test command to prepare-code
- disable strictPropertyInitialization flag in tsconfig which creates issues with adonis models
- update precommit hook to excute pnpm prepare-code
- remove ts-ignore statements from all models
* fix node and pnpm dependency update
* add cross env (so that we can develop on windows)
* add signup endpoint (TODO: JWT auth)
* Add login endpoint
* Add me and updateMe endpoints
* Add service endpoint
* refactor: change endpoints to use jwt
* add recipes endpoint
* add workspaces endpoint
* fix web controllors for login and post import
* Update node deps
* Change auth middleware (for web) and exempt api from CSRF
* Add import endpoint (franz import)
* Fix export/import logic
* Fix service and workspace data in user/data
* Fix partial lint
* chore: workaround lint issues
* fix: migration naming had two .
* Sync back node with recipes repo
* Temporarily ignore typescript
* Fix adonisrc to handle public folder static assets
* Fix issue with production database
* add Legacy Password Provider
* Fix lint errors
* Fix issue on login errors frontend
* add Legacy Password Provider
* Fix issue with customIcons
* Fix issue with auth tokens
* Update 'node' to '18.18.0'
* make docker work
* improve docker entrypoint (test api performance)
* Add migration database script
* NODE_ENV on recipes
* prefer @ts-expect-error over @ts-ignore
* small fixes
* Update 'pnpm' to '8.7.6'
* fix error catch
* Automatically generate JWT Public and Private keys
* Use custom Adonis5-jwt
* Update code to use secret (old way, no breaking changes)
* Normalize appKey
* Trick to make JWT tokens on client work with new version
* Fix error with new JWT logic
* Change migration and how we store JWT
* Fix 500 response code (needs to be 401)
* Improve logic and fix bugs
* Fix build and entrypoint logic
* Catch error if appKey changes
* Add newToken logic
* Fix lint (ignore any errors)
* Add build for PRs
* pnpm reformat-files result
* Fix some tests
* Fix reset password not working (test failing)
* Restore csrfTokens (disabled by accident)
* Fix pnpm start command with .env
* Disable failing tests on the transfer endpoint (TODO)
* Add tests to PR build
* Fix build
* Remove unnecessary assertStatus
* Add typecheck
* hash password on UserFactory (fix build)
* Add JWT_USE_PEM true by default (increase security)
* fix name of github action
---------
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Co-authored-by: Balaji Vijayakumar <kuttibalaji.v6@gmail.com>
Co-authored-by: MCMXC <16797721+mcmxcdev@users.noreply.github.com>
Co-authored-by: André Oliveira <oliveira.andrerodrigues95@gmail.com>
Diffstat (limited to 'start/routes.js')
-rw-r--r-- | start/routes.js | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/start/routes.js b/start/routes.js deleted file mode 100644 index 0f3785f..0000000 --- a/start/routes.js +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | Routes | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | */ | ||
7 | |||
8 | /** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */ | ||
9 | const Route = use('Route'); | ||
10 | const Env = use('Env'); | ||
11 | |||
12 | // Health: Returning if all systems function correctly | ||
13 | Route.get('health', ({ | ||
14 | response, | ||
15 | }) => response.send({ | ||
16 | api: 'success', | ||
17 | db: 'success', | ||
18 | })); | ||
19 | |||
20 | // API is grouped under '/v1/' route | ||
21 | Route.group(() => { | ||
22 | // User authentification | ||
23 | Route.post('auth/signup', 'UserController.signup').middleware('guest'); | ||
24 | Route.post('auth/login', 'UserController.login').middleware('guest'); | ||
25 | |||
26 | // User info | ||
27 | Route.get('me', 'UserController.me').middleware('auth'); | ||
28 | Route.put('me', 'UserController.updateMe').middleware('auth'); | ||
29 | |||
30 | // Service info | ||
31 | Route.post('service', 'ServiceController.create').middleware('auth'); | ||
32 | Route.put('service/reorder', 'ServiceController.reorder').middleware('auth'); | ||
33 | Route.put('service/:id', 'ServiceController.edit').middleware('auth'); | ||
34 | Route.delete('service/:id', 'ServiceController.delete').middleware('auth'); | ||
35 | Route.get('me/services', 'ServiceController.list').middleware('auth'); | ||
36 | Route.get('recipe', 'ServiceController.list').middleware('auth'); | ||
37 | Route.get('icon/:id', 'ServiceController.icon'); | ||
38 | |||
39 | // Recipe store | ||
40 | Route.get('recipes', 'RecipeController.list'); | ||
41 | Route.get('recipes/search', 'RecipeController.search'); | ||
42 | Route.get('recipes/popular', 'RecipeController.popularRecipes'); | ||
43 | Route.get('recipes/download/:recipe', 'RecipeController.download'); | ||
44 | Route.post('recipes/update', 'RecipeController.update'); | ||
45 | |||
46 | // Workspaces | ||
47 | Route.put('workspace/:id', 'WorkspaceController.edit').middleware('auth'); | ||
48 | Route.delete('workspace/:id', 'WorkspaceController.delete').middleware('auth'); | ||
49 | Route.post('workspace', 'WorkspaceController.create').middleware('auth'); | ||
50 | Route.get('workspace', 'WorkspaceController.list').middleware('auth'); | ||
51 | |||
52 | // Static responses | ||
53 | Route.get('features/:mode?', 'StaticController.features'); | ||
54 | Route.get('services', 'StaticController.emptyArray'); | ||
55 | Route.get('news', 'StaticController.emptyArray'); | ||
56 | Route.get('announcements/:version', 'StaticController.announcement'); | ||
57 | }).prefix('v1'); | ||
58 | |||
59 | // User dashboard | ||
60 | if (Env.get('IS_DASHBOARD_ENABLED') !== 'false') { | ||
61 | Route.group(() => { | ||
62 | // Auth | ||
63 | Route.get('login', ({ view }) => view.render('dashboard.login')).middleware('guest'); | ||
64 | Route.post('login', 'DashboardController.login').middleware('guest').as('login'); | ||
65 | |||
66 | // Reset password | ||
67 | Route.get('forgot', ({ view }) => view.render('dashboard.forgotPassword')).middleware('guest'); | ||
68 | Route.post('forgot', 'DashboardController.forgotPassword').middleware('guest'); | ||
69 | |||
70 | Route.get('reset', ({ view, request }) => { | ||
71 | const { token } = request.get(); | ||
72 | if (token) { | ||
73 | return view.render('dashboard.resetPassword', { token }); | ||
74 | } | ||
75 | return view.render('others.message', { | ||
76 | heading: 'Invalid token', | ||
77 | text: 'Please make sure you are using a valid and recent link to reset your password.', | ||
78 | }); | ||
79 | }).middleware('guest'); | ||
80 | Route.post('reset', 'DashboardController.resetPassword').middleware('guest'); | ||
81 | |||
82 | // Dashboard | ||
83 | Route.get('account', 'DashboardController.account').middleware('auth:session'); | ||
84 | Route.post('account', 'DashboardController.edit').middleware('auth:session'); | ||
85 | |||
86 | Route.get('data', 'DashboardController.data').middleware('auth:session'); | ||
87 | |||
88 | Route.get('export', 'DashboardController.export').middleware('auth:session'); | ||
89 | Route.post('transfer', 'DashboardController.import').middleware('auth:session'); | ||
90 | Route.get('transfer', ({ view }) => view.render('dashboard.transfer')).middleware('auth:session'); | ||
91 | |||
92 | Route.get('delete', ({ view }) => view.render('dashboard.delete')).middleware('auth:session'); | ||
93 | Route.post('delete', 'DashboardController.delete').middleware('auth:session'); | ||
94 | |||
95 | Route.get('logout', 'DashboardController.logout').middleware('auth:session'); | ||
96 | |||
97 | Route.get('*', ({ response }) => response.redirect('/user/account')); | ||
98 | }).prefix('user').middleware('shield'); | ||
99 | } else { | ||
100 | Route.group(() => { | ||
101 | Route.get('*', ({ | ||
102 | response, | ||
103 | }) => response.send('The user dashboard is disabled on this server\n\nIf you are the server owner, please set IS_DASHBOARD_ENABLED to true to enable the dashboard.')); | ||
104 | }).prefix('user'); | ||
105 | } | ||
106 | |||
107 | // Recipe creation | ||
108 | Route.post('new', 'RecipeController.create'); | ||
109 | Route.get('new', ({ response, view }) => { | ||
110 | if (Env.get('IS_CREATION_ENABLED') == 'false') { // eslint-disable-line eqeqeq | ||
111 | return response.send('This server doesn\'t allow the creation of new recipes.\n\nIf you are the server owner, please set IS_CREATION_ENABLED to true to enable recipe creation.'); | ||
112 | } | ||
113 | return view.render('others.new'); | ||
114 | }); | ||
115 | |||
116 | // Franz/Ferdi account import | ||
117 | Route.post('import', 'UserController.import'); | ||
118 | Route.get('import', ({ view }) => view.render('others.import')); | ||
119 | |||
120 | // Legal documents | ||
121 | Route.get('terms', ({ response }) => response.redirect('/terms.html')); | ||
122 | Route.get('privacy', ({ response }) => response.redirect('/privacy.html')); | ||
123 | |||
124 | // Index | ||
125 | Route.get('/', ({ view }) => view.render('others.index')); | ||
126 | |||
127 | // 404 handler | ||
128 | Route.get('/*', ({ response }) => response.redirect('/')); | ||