@@ -8,11 +8,13 @@ class Strapi extends Hookable {
8
8
constructor ( ctx ) {
9
9
super ( )
10
10
11
+ ctx . $config = ctx . $config || { } // fallback for Nuxt < 2.13
12
+ const runtimeConfig = ctx . $config . strapi || { }
11
13
this . state = Vue . observable ( { user : null } )
12
14
13
15
this . $cookies = ctx . app . $cookies
14
16
this . $http = ctx . $http . create ( { } )
15
- this . $http . setBaseURL ( '<%= options.url %>' )
17
+ this . $http . setBaseURL ( runtimeConfig . url || '<%= options.url %>' )
16
18
this . $http . onError ( ( err ) => {
17
19
const { response : { data : { message : msg } } } = err
18
20
@@ -139,32 +141,32 @@ class Strapi extends Hookable {
139
141
140
142
export default async function ( ctx , inject ) {
141
143
< %= JSON . stringify ( options . entities ) % > . forEach ( ( entity ) => {
142
- Object . defineProperty ( Strapi . prototype , `$${ entity } ` , {
143
- get : function ( ) {
144
- const that = this
145
- return {
146
- find : function ( ...args ) {
147
- return that . find ( entity , ...args )
148
- } ,
149
- findOne : function ( ...args ) {
150
- return that . findOne ( entity , ...args )
151
- } ,
152
- count : function ( ...args ) {
153
- return that . count ( entity , ...args )
154
- } ,
155
- create : function ( ...args ) {
156
- return that . create ( entity , ...args )
157
- } ,
158
- update : function ( ...args ) {
159
- return that . update ( entity , ...args )
160
- } ,
161
- delete : function ( ...args ) {
162
- return that . delete ( entity , ...args )
144
+ Object . defineProperty ( Strapi . prototype , `$${ entity } ` , {
145
+ get ( ) {
146
+ const that = this
147
+ return {
148
+ find ( ...args ) {
149
+ return that . find ( entity , ...args )
150
+ } ,
151
+ findOne ( ...args ) {
152
+ return that . findOne ( entity , ...args )
153
+ } ,
154
+ count ( ...args ) {
155
+ return that . count ( entity , ...args )
156
+ } ,
157
+ create ( ...args ) {
158
+ return that . create ( entity , ...args )
159
+ } ,
160
+ update ( ...args ) {
161
+ return that . update ( entity , ...args )
162
+ } ,
163
+ delete ( ...args ) {
164
+ return that . delete ( entity , ...args )
165
+ }
163
166
}
164
167
}
165
- }
168
+ } )
166
169
} )
167
- } )
168
170
169
171
const strapi = new Strapi ( ctx )
170
172
0 commit comments