diff options
author | 2021-08-01 11:07:57 +0000 | |
---|---|---|
committer | 2021-08-01 16:37:57 +0530 | |
commit | 419933f6505caf4c5e685f8436b1ff735185e55a (patch) | |
tree | 152dcb9d2b35d29f862cc57a605b9ae2a0f7c300 /src/internal-server/start/routes.js | |
parent | Removed duplicated contributors badge. (diff) | |
download | ferdium-app-419933f6505caf4c5e685f8436b1ff735185e55a.tar.gz ferdium-app-419933f6505caf4c5e685f8436b1ff735185e55a.tar.zst ferdium-app-419933f6505caf4c5e685f8436b1ff735185e55a.zip |
Moved 'internal-server' into a sub-folder as opposed to a git submodule. (#1715)
* Ignored tests in 'internal-server' folder since there are none.
* Linter fixes
Diffstat (limited to 'src/internal-server/start/routes.js')
-rw-r--r-- | src/internal-server/start/routes.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/internal-server/start/routes.js b/src/internal-server/start/routes.js new file mode 100644 index 000000000..63ac42c47 --- /dev/null +++ b/src/internal-server/start/routes.js | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | Routes | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | */ | ||
7 | |||
8 | /** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */ | ||
9 | const Route = use('Route'); | ||
10 | |||
11 | // Run latest database migration | ||
12 | const migrate = require('./migrate'); | ||
13 | |||
14 | migrate(); | ||
15 | |||
16 | const OnlyAllowFerdi = async ({ request, response }, next) => { | ||
17 | const version = request.header('X-Franz-Version'); | ||
18 | if (!version) { | ||
19 | return response.status(403).redirect('/'); | ||
20 | } | ||
21 | |||
22 | await next(); | ||
23 | return true; | ||
24 | }; | ||
25 | |||
26 | // Health: Returning if all systems function correctly | ||
27 | Route.get('health', ({ | ||
28 | response, | ||
29 | }) => response.send({ | ||
30 | api: 'success', | ||
31 | db: 'success', | ||
32 | })).middleware(OnlyAllowFerdi); | ||
33 | |||
34 | // API is grouped under '/v1/' route | ||
35 | Route.group(() => { | ||
36 | // User authentification | ||
37 | Route.post('auth/signup', 'UserController.signup'); | ||
38 | Route.post('auth/login', 'UserController.login'); | ||
39 | |||
40 | // User info | ||
41 | Route.get('me', 'UserController.me'); | ||
42 | Route.put('me', 'UserController.updateMe'); | ||
43 | |||
44 | // Service info | ||
45 | Route.post('service', 'ServiceController.create'); | ||
46 | Route.put('service/reorder', 'ServiceController.reorder'); | ||
47 | Route.put('service/:id', 'ServiceController.edit'); | ||
48 | Route.delete('service/:id', 'ServiceController.delete'); | ||
49 | Route.get('me/services', 'ServiceController.list'); | ||
50 | |||
51 | // Recipe store | ||
52 | Route.get('recipe', 'ServiceController.list'); | ||
53 | Route.post('recipes/update', 'ServiceController.update'); | ||
54 | Route.get('recipes', 'RecipeController.list'); | ||
55 | Route.get('recipes/download/:recipe', 'RecipeController.download'); | ||
56 | Route.get('recipes/search', 'RecipeController.search'); | ||
57 | Route.get('recipes/popular', 'StaticController.popularRecipes'); | ||
58 | Route.get('recipes/update', 'StaticController.emptyArray'); | ||
59 | |||
60 | // Workspaces | ||
61 | Route.put('workspace/:id', 'WorkspaceController.edit'); | ||
62 | Route.delete('workspace/:id', 'WorkspaceController.delete'); | ||
63 | Route.post('workspace', 'WorkspaceController.create'); | ||
64 | Route.get('workspace', 'WorkspaceController.list'); | ||
65 | |||
66 | // Static responses | ||
67 | Route.get('features/:mode?', 'StaticController.features'); | ||
68 | Route.get('services', 'StaticController.emptyArray'); | ||
69 | Route.get('news', 'StaticController.emptyArray'); | ||
70 | Route.get('announcements/:version', 'StaticController.announcement'); | ||
71 | }).prefix('v1').middleware(OnlyAllowFerdi); | ||
72 | |||
73 | Route.group(() => { | ||
74 | Route.get('icon/:id', 'ServiceController.icon'); | ||
75 | }).prefix('v1'); | ||
76 | |||
77 | // Franz account import | ||
78 | Route.post('import', 'UserController.import'); | ||
79 | Route.get('import', ({ view }) => view.render('import')); | ||
80 | |||
81 | // Account transfer | ||
82 | Route.get('export', 'UserController.export'); | ||
83 | Route.post('transfer', 'UserController.importFerdi'); | ||
84 | Route.get('transfer', ({ view }) => view.render('transfer')); | ||
85 | |||
86 | // Index | ||
87 | Route.get('/', ({ view }) => view.render('index')); | ||