-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.ts
74 lines (64 loc) · 1.87 KB
/
index.ts
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
/*
* @adonisjs/http-server
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { join } from 'path'
import proxyaddr from 'proxy-addr'
import { Filesystem } from '@poppinss/dev-utils'
import { Application } from '@adonisjs/application'
import { ServerConfig } from '@ioc:Adonis/Core/Server'
import { RequestConfig } from '@ioc:Adonis/Core/Request'
import { ResponseConfig } from '@ioc:Adonis/Core/Response'
import { Encryption } from '@adonisjs/encryption/build/standalone'
export const appSecret = 'averylongrandom32charslongsecret'
export const fs = new Filesystem(join(__dirname, './app'))
export const loggerConfig = {
name: 'http-server',
enabled: true,
level: 'debug',
}
export const requestConfig: RequestConfig = {
allowMethodSpoofing: false,
trustProxy: proxyaddr.compile('loopback'),
subdomainOffset: 2,
generateRequestId: true,
enableAsyncHttpContext: Boolean(process.env.ASYNC_HOOKS),
}
export const responseConfig: ResponseConfig = {
etag: false,
jsonpCallbackName: 'callback',
cookie: {
maxAge: 90,
path: '/',
httpOnly: true,
sameSite: false,
secure: false,
},
}
export const serverConfig: ServerConfig = Object.assign({}, requestConfig, responseConfig)
export const encryption = new Encryption({ secret: appSecret })
export async function setupApp(providers?: string[]) {
const app = new Application(fs.basePath, 'web', {
providers: providers || [],
})
await fs.add('.env', '')
await fs.add(
'config/app.ts',
`
export const appKey = '${appSecret}'
export const http = {
trustProxy: () => true,
cookie: {},
enableAsyncHttpContext: ${process.env.ASYNC_HOOKS ? 'true' : 'false'}
}
`
)
app.setup()
app.registerProviders()
await app.bootProviders()
return app
}