diff options
Diffstat (limited to 'start')
-rw-r--r-- | start/app.js | 58 | ||||
-rw-r--r-- | start/kernel.js | 61 | ||||
-rw-r--r-- | start/routes.js | 55 |
3 files changed, 174 insertions, 0 deletions
diff --git a/start/app.js b/start/app.js new file mode 100644 index 0000000..5e4df28 --- /dev/null +++ b/start/app.js | |||
@@ -0,0 +1,58 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | /* | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | Providers | ||
6 | |-------------------------------------------------------------------------- | ||
7 | | | ||
8 | | Providers are building blocks for your Adonis app. Anytime you install | ||
9 | | a new Adonis specific package, chances are you will register the | ||
10 | | provider here. | ||
11 | | | ||
12 | */ | ||
13 | const providers = [ | ||
14 | '@adonisjs/framework/providers/AppProvider', | ||
15 | '@adonisjs/auth/providers/AuthProvider', | ||
16 | '@adonisjs/bodyparser/providers/BodyParserProvider', | ||
17 | '@adonisjs/cors/providers/CorsProvider', | ||
18 | '@adonisjs/lucid/providers/LucidProvider' | ||
19 | ] | ||
20 | |||
21 | /* | ||
22 | |-------------------------------------------------------------------------- | ||
23 | | Ace Providers | ||
24 | |-------------------------------------------------------------------------- | ||
25 | | | ||
26 | | Ace providers are required only when running ace commands. For example | ||
27 | | Providers for migrations, tests etc. | ||
28 | | | ||
29 | */ | ||
30 | const aceProviders = [ | ||
31 | '@adonisjs/lucid/providers/MigrationsProvider' | ||
32 | ] | ||
33 | |||
34 | /* | ||
35 | |-------------------------------------------------------------------------- | ||
36 | | Aliases | ||
37 | |-------------------------------------------------------------------------- | ||
38 | | | ||
39 | | Aliases are short unique names for IoC container bindings. You are free | ||
40 | | to create your own aliases. | ||
41 | | | ||
42 | | For example: | ||
43 | | { Route: 'Adonis/Src/Route' } | ||
44 | | | ||
45 | */ | ||
46 | const aliases = {} | ||
47 | |||
48 | /* | ||
49 | |-------------------------------------------------------------------------- | ||
50 | | Commands | ||
51 | |-------------------------------------------------------------------------- | ||
52 | | | ||
53 | | Here you store ace commands for your package | ||
54 | | | ||
55 | */ | ||
56 | const commands = [] | ||
57 | |||
58 | module.exports = { providers, aceProviders, aliases, commands } | ||
diff --git a/start/kernel.js b/start/kernel.js new file mode 100644 index 0000000..b56b58b --- /dev/null +++ b/start/kernel.js | |||
@@ -0,0 +1,61 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | /** @type {import('@adonisjs/framework/src/Server')} */ | ||
4 | const Server = use('Server') | ||
5 | |||
6 | /* | ||
7 | |-------------------------------------------------------------------------- | ||
8 | | Global Middleware | ||
9 | |-------------------------------------------------------------------------- | ||
10 | | | ||
11 | | Global middleware are executed on each http request only when the routes | ||
12 | | match. | ||
13 | | | ||
14 | */ | ||
15 | const globalMiddleware = [ | ||
16 | 'Adonis/Middleware/BodyParser', | ||
17 | 'App/Middleware/ConvertEmptyStringsToNull', | ||
18 | 'Adonis/Middleware/AuthInit' | ||
19 | ] | ||
20 | |||
21 | /* | ||
22 | |-------------------------------------------------------------------------- | ||
23 | | Named Middleware | ||
24 | |-------------------------------------------------------------------------- | ||
25 | | | ||
26 | | Named middleware is key/value object to conditionally add middleware on | ||
27 | | specific routes or group of routes. | ||
28 | | | ||
29 | | // define | ||
30 | | { | ||
31 | | auth: 'Adonis/Middleware/Auth' | ||
32 | | } | ||
33 | | | ||
34 | | // use | ||
35 | | Route.get().middleware('auth') | ||
36 | | | ||
37 | */ | ||
38 | const namedMiddleware = { | ||
39 | auth: 'Adonis/Middleware/Auth', | ||
40 | guest: 'Adonis/Middleware/AllowGuestOnly' | ||
41 | } | ||
42 | |||
43 | /* | ||
44 | |-------------------------------------------------------------------------- | ||
45 | | Server Middleware | ||
46 | |-------------------------------------------------------------------------- | ||
47 | | | ||
48 | | Server level middleware are executed even when route for a given URL is | ||
49 | | not registered. Features like `static assets` and `cors` needs better | ||
50 | | control over request lifecycle. | ||
51 | | | ||
52 | */ | ||
53 | const serverMiddleware = [ | ||
54 | // 'Adonis/Middleware/Static', | ||
55 | 'Adonis/Middleware/Cors' | ||
56 | ] | ||
57 | |||
58 | Server | ||
59 | .registerGlobal(globalMiddleware) | ||
60 | .registerNamed(namedMiddleware) | ||
61 | .use(serverMiddleware) | ||
diff --git a/start/routes.js b/start/routes.js new file mode 100644 index 0000000..3aca58e --- /dev/null +++ b/start/routes.js | |||
@@ -0,0 +1,55 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | /* | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | Routes | ||
6 | |-------------------------------------------------------------------------- | ||
7 | | | ||
8 | */ | ||
9 | |||
10 | /** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */ | ||
11 | const Route = use('Route') | ||
12 | |||
13 | // Health: Returning if all systems function correctly | ||
14 | Route.get('health', ({ | ||
15 | response | ||
16 | }) => { | ||
17 | return response.send({ | ||
18 | api: 'success', | ||
19 | db: 'success' | ||
20 | }) | ||
21 | }) | ||
22 | |||
23 | // API is grouped under '/v1/' route | ||
24 | Route.group(() => { | ||
25 | // User authentification | ||
26 | Route.post('auth/signup', 'UserController.signup').middleware('guest') | ||
27 | Route.post('auth/login', 'UserController.login').middleware('guest') | ||
28 | |||
29 | // User info | ||
30 | Route.get('me', 'UserController.me').middleware('auth') | ||
31 | |||
32 | // Service/recipe info | ||
33 | Route.post('service', 'ServiceController.create').middleware('auth') | ||
34 | Route.get('me/services', 'ServiceController.list').middleware('auth') | ||
35 | Route.get('recipes/download/:recipe', 'ServiceController.download') | ||
36 | |||
37 | // Static responses | ||
38 | Route.get('features', 'StaticController.features'); | ||
39 | Route.get('services', 'StaticController.emptyArray') | ||
40 | Route.get('workspace', 'StaticController.emptyArray') | ||
41 | Route.get('news', 'StaticController.emptyArray') | ||
42 | Route.get('payment/plans', 'StaticController.plans') | ||
43 | Route.get('recipes/popular', 'StaticController.popularRecipes') | ||
44 | Route.get('recipes/update', 'StaticController.emptyArray') | ||
45 | Route.get('announcements/:version', 'StaticController.announcement') | ||
46 | }).prefix('v1') | ||
47 | |||
48 | Route.get('/', () => { | ||
49 | return { | ||
50 | info: 'Franz Unofficial Server', | ||
51 | version: '1.0.0', | ||
52 | author: 'vantezzen', | ||
53 | repo: 'https://github.com/vantezzen/franz-server' | ||
54 | } | ||
55 | }) | ||