-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuxt.ts
90 lines (76 loc) · 1.9 KB
/
nuxt.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Module } from '@nuxt/types'
import { join, resolve } from 'path'
import 'reflect-metadata'
interface SDKModuleParams {
client: string
domain: string
api: string
proxy?: string
}
export const MerkalySDK: Module<SDKModuleParams> = async function (params) {
const { options } = this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options.publicRuntimeConfig.merkaly = {
api: params.api || 'https://api.merkaly.io',
client: params.client,
domain: params.domain,
proxy: params.proxy || '/api'
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const merkaly = options.publicRuntimeConfig.merkaly
await this.addTemplate({
src: resolve(__dirname, './nuxt.auth.ts'),
filename: './nuxt.auth.ts'
})
await this.addTemplate({
src: resolve(__dirname, './nuxt.axios.ts'),
filename: './nuxt.axios.ts'
})
options.auth = {
...options.auth,
plugins: [join(options.buildDir, './nuxt.auth.ts')],
strategies: {
auth0: {
domain: merkaly.domain,
clientId: merkaly.client
}
}
}
options.axios = {
...options.axios,
proxy: true,
https: true
}
const target = merkaly.api.split('//').pop()
options.proxy = {
...options.proxy,
[`${merkaly.proxy}`]: {
target: `http://${target}`,
pathRewrite: { [`^${merkaly.proxy}`]: '' }
}
}
options.build = {
...options.build,
standalone: true
}
this.addModule({
src: '@nuxtjs/axios',
options: options.axios
})
this.addModule({
src: '@nuxtjs/auth-next',
options: options.auth
})
this.addModule({
src: '@nuxtjs/proxy',
options: options.proxy
})
if (merkaly.api) {
options.cli.badgeMessages.push(`-> API: /${merkaly.proxy} -> ${merkaly.api}`)
}
if (merkaly.domain) {
options.cli.badgeMessages.push(`-> AUTH0: https://${merkaly.domain}`)
}
}