aboutsummaryrefslogtreecommitdiffstats
path: root/start
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-08-22 11:12:36 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-08-22 11:12:36 +0200
commitb018adf240679ec59a7344e30be39400f1ecd8af (patch)
treec076635761667dad302716b498088f1047281e46 /start
downloadferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.tar.gz
ferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.tar.zst
ferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.zip
Initial commit
Diffstat (limited to 'start')
-rw-r--r--start/app.js58
-rw-r--r--start/kernel.js61
-rw-r--r--start/routes.js55
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*/
13const 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*/
30const 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*/
46const aliases = {}
47
48/*
49|--------------------------------------------------------------------------
50| Commands
51|--------------------------------------------------------------------------
52|
53| Here you store ace commands for your package
54|
55*/
56const commands = []
57
58module.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')} */
4const 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*/
15const 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*/
38const 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*/
53const serverMiddleware = [
54 // 'Adonis/Middleware/Static',
55 'Adonis/Middleware/Cors'
56]
57
58Server
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')} */
11const Route = use('Route')
12
13// Health: Returning if all systems function correctly
14Route.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
24Route.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
48Route.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})