-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.js
109 lines (100 loc) · 3.63 KB
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict'
/*
|--------------------------------------------------------------------------
| HTTP Server Setup
|--------------------------------------------------------------------------
|
| Here we join different pieces and start the HTTP server. It will be
| a matter of seconds to start your shiny Adonis application.
|
*/
const app = require('./app')
const fold = require('adonis-fold')
const path = require('path')
const packageFile = path.join(__dirname, '../package.json')
require('./extend')
module.exports = function (callback) {
fold.Registrar
.register(app.providers)
.then(() => {
/*
|--------------------------------------------------------------------------
| Register Aliases
|--------------------------------------------------------------------------
|
| After registering all the providers, we need to setup aliases so that
| providers can be referenced with short sweet names.
|
*/
fold.Ioc.aliases(app.aliases)
/*
|--------------------------------------------------------------------------
| Register Package File
|--------------------------------------------------------------------------
|
| Adonis application package.json file has the reference to the autoload
| directory. Here we register the package file with the Helpers provider
| to setup autoloading.
|
*/
const Helpers = use('Helpers')
const Env = use('Env')
Helpers.load(packageFile, fold.Ioc)
/*
|--------------------------------------------------------------------------
| Register Events
|--------------------------------------------------------------------------
|
| Here we require the event.js file to register events defined inside
| events.js file.
|
*/
require('./events')
/*
|--------------------------------------------------------------------------
| Load Middleware And Routes
|--------------------------------------------------------------------------
|
| Middleware and Routes are required to oil up your HTTP server. Here we
| require defined files for same.
|
*/
use(Helpers.makeNameSpace('Http', 'kernel'))
use(Helpers.makeNameSpace('Http', 'routes'))
/*
|--------------------------------------------------------------------------
| Load Websocket Channels And Middleware
|--------------------------------------------------------------------------
|
| Websocket channels defination should be loaded before firing the Http
| server.
|
*/
use(Helpers.makeNameSpace('Ws', 'kernel'))
use(Helpers.makeNameSpace('Ws', 'socket'))
/*
|--------------------------------------------------------------------------
| Load Database Factory
|--------------------------------------------------------------------------
|
| All database/model blueprints are defined inside the below file. We
| autoload it to be used inside the entire application.
|
*/
use(Helpers.databasePath('factory'))
/*
|--------------------------------------------------------------------------
| Start Http Server
|--------------------------------------------------------------------------
|
| We are all set to fire the Http Server and start receiving new requests.
|
*/
const Server = use('Adonis/Src/Server')
Server.listen(Env.get('HOST'), Env.get('PORT'))
if (typeof (callback) === 'function') {
callback()
}
})
.catch((error) => console.error(error.stack))
}