@@ -1907,54 +1907,38 @@ export default class Elysia<
1907
1907
Object . assign ( context . store , this . store )
1908
1908
} )
1909
1909
1910
- plugin . event . trace = [
1911
- ...( this . event . trace || [ ] ) ,
1912
- ...( plugin . event . trace || [ ] )
1913
- ]
1914
-
1915
-
1910
+ if ( plugin . event . trace . length )
1911
+ plugin . event . trace . push ( ...plugin . event . trace )
1916
1912
1917
1913
if ( isScoped && ! plugin . config . prefix )
1918
1914
console . warn (
1919
1915
'When using scoped plugins it is recommended to use a prefix, else routing may not work correctly for the second scoped instance'
1920
- )
1916
+ )
1917
+
1918
+ if ( plugin . event . error . length )
1919
+ plugin . event . error . push ( ...this . event . error )
1921
1920
1922
- /* Run global error handlers after the error handlers of the plugin are done executing.
1923
- TODO
1924
- - should this really be handled here or is there some kind of merging failing?
1925
- - should this also be applicable for other handlers?
1926
- It seems like this only affects scoped changes. so it could be moved inside the below if block */
1927
-
1928
- plugin . event . error . push ( ...this . event . error ) ;
1929
-
1930
1921
if ( plugin . config . aot ) plugin . compile ( )
1931
1922
1932
1923
let instance
1933
1924
1934
1925
if ( isScoped && plugin . config . prefix ) {
1935
-
1936
1926
instance = this . mount ( plugin . config . prefix + '/' , plugin . fetch )
1937
1927
1938
- //Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.
1939
- //This also avoids adding routes multiple times.
1940
-
1941
- plugin . routes . forEach ( ( r ) => {
1928
+ // Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.
1929
+ // This also avoids adding routes multiple times.
1930
+ for ( const route of plugin . routes )
1942
1931
this . routes . push ( {
1943
- ...r ,
1944
- path : `${ plugin . config . prefix } ${ r . path } ` ,
1945
- //This probably has no effect as the routes object itself is not used to execute these handlers? The plugin is taking care of it.
1946
- hooks : mergeHook (
1947
- r . hooks ,
1948
- {
1949
- error : this . event . error
1950
- }
1951
- )
1932
+ ...route ,
1933
+ path : `${ plugin . config . prefix } ${ route . path } ` ,
1934
+ hooks : mergeHook ( route . hooks , {
1935
+ error : this . event . error
1936
+ } )
1952
1937
} )
1953
- } )
1954
1938
} else {
1955
-
1956
1939
instance = this . mount ( plugin . fetch )
1957
- this . routes = this . routes . concat ( instance . routes )
1940
+
1941
+ if ( instance . routes . length ) this . routes . push ( ...instance . routes )
1958
1942
}
1959
1943
1960
1944
return this
0 commit comments