30
30
import com .hellokaton .blade .mvc .hook .WebHook ;
31
31
import com .hellokaton .blade .mvc .http .HttpMethod ;
32
32
import com .hellokaton .blade .mvc .http .session .SessionManager ;
33
- import com .hellokaton .blade .mvc .route .DynamicMapping ;
34
33
import com .hellokaton .blade .mvc .route .RouteMatcher ;
35
- import com .hellokaton .blade .mvc .route .mapping .dynamic .RegexMapping ;
36
- import com .hellokaton .blade .mvc .route .mapping .dynamic .TrieMapping ;
37
34
import com .hellokaton .blade .mvc .ui .template .DefaultEngine ;
38
35
import com .hellokaton .blade .mvc .ui .template .TemplateEngine ;
39
36
import com .hellokaton .blade .options .CorsOptions ;
40
37
import com .hellokaton .blade .options .HttpOptions ;
38
+ import com .hellokaton .blade .options .StaticOptions ;
41
39
import com .hellokaton .blade .server .NettyServer ;
42
40
import com .hellokaton .blade .server .Server ;
43
41
import lombok .AccessLevel ;
54
52
import java .util .function .Consumer ;
55
53
import java .util .stream .Collectors ;
56
54
55
+ import static com .hellokaton .blade .mvc .BladeConst .ENV_KEY_FAVICON_DIR ;
56
+
57
57
/**
58
58
* Blade Core
59
59
* <p>
@@ -78,13 +78,6 @@ public class Blade {
78
78
*/
79
79
private final Set <String > packages = new LinkedHashSet <>(BladeConst .PLUGIN_PACKAGE_NAME );
80
80
81
- /**
82
- * All static resource URL prefixes,
83
- * defaults to "/favicon.ico", "/robots.txt", "/static/", "/upload/", "/webjars/",
84
- * which are located under classpath
85
- */
86
- private final Set <String > statics = new HashSet <>(BladeConst .DEFAULT_STATICS );
87
-
88
81
/**
89
82
* The default IOC container implementation
90
83
*/
@@ -121,7 +114,8 @@ public class Blade {
121
114
private final RouteMatcher routeMatcher = new RouteMatcher ();
122
115
123
116
private CorsOptions corsOptions = null ;
124
- private final HttpOptions httpOptions = HttpOptions .create ();
117
+ private HttpOptions httpOptions = HttpOptions .create ();
118
+ private StaticOptions staticOptions = StaticOptions .create ();
125
119
126
120
/**
127
121
* Blade environment, which stores the parameters of the application.properties configuration file
@@ -280,6 +274,17 @@ public TemplateEngine templateEngine() {
280
274
return this .templateEngine ;
281
275
}
282
276
277
+ /**
278
+ * setting favicon dir, default is /static
279
+ *
280
+ * @param faviconDir favicon dir
281
+ * @return blade instance
282
+ */
283
+ public Blade faviconDir (String faviconDir ) {
284
+ this .setEnv (ENV_KEY_FAVICON_DIR , faviconDir );
285
+ return this ;
286
+ }
287
+
283
288
/**
284
289
* Get RouteMatcher
285
290
*
@@ -294,6 +299,21 @@ public Blade http(Consumer<HttpOptions> consumer) {
294
299
return this ;
295
300
}
296
301
302
+ public Blade http (HttpOptions httpOptions ) {
303
+ this .httpOptions = httpOptions ;
304
+ return this ;
305
+ }
306
+
307
+ public Blade staticOptions (Consumer <StaticOptions > consumer ) {
308
+ consumer .accept (this .staticOptions );
309
+ return this ;
310
+ }
311
+
312
+ public Blade staticOptions (StaticOptions staticOptions ) {
313
+ this .staticOptions = staticOptions ;
314
+ return this ;
315
+ }
316
+
297
317
public Blade cors (CorsOptions corsOptions ) {
298
318
this .corsOptions = corsOptions ;
299
319
return this ;
@@ -307,6 +327,10 @@ public HttpOptions httpOptions() {
307
327
return this .httpOptions ;
308
328
}
309
329
330
+ public StaticOptions staticOptions () {
331
+ return this .staticOptions ;
332
+ }
333
+
310
334
/**
311
335
* Register bean to ioc container
312
336
*
@@ -329,29 +353,6 @@ public Blade register(@NonNull Class<?> cls) {
329
353
return this ;
330
354
}
331
355
332
- /**
333
- * Add multiple static resource file
334
- * the default provides the static, upload
335
- *
336
- * @param folders static resource directory
337
- * @return blade
338
- */
339
- public Blade addStatics (@ NonNull String ... folders ) {
340
- this .statics .addAll (Arrays .asList (folders ));
341
- return this ;
342
- }
343
-
344
- /**
345
- * Set whether to show the file directory, default doesn't show
346
- *
347
- * @param fileList show the file directory
348
- * @return blade
349
- */
350
- public Blade showFileList (boolean fileList ) {
351
- this .environment .set (BladeConst .ENV_KEY_STATIC_LIST , fileList );
352
- return this ;
353
- }
354
-
355
356
/**
356
357
* Get ioc bean
357
358
*
@@ -415,16 +416,6 @@ public Class<?> bootClass() {
415
416
return this .bootClass ;
416
417
}
417
418
418
- /**
419
- * Get blade statics list.
420
- * e.g: "/favicon.ico", "/robots.txt", "/static/", "/upload/", "/webjars/"
421
- *
422
- * @return return statics
423
- */
424
- public Set <String > getStatics () {
425
- return this .statics ;
426
- }
427
-
428
419
/**
429
420
* When set to start blade scan packages
430
421
*
@@ -686,8 +677,8 @@ public Blade start(Class<?> mainCls, String... args) {
686
677
try {
687
678
//TODO: add support for Create and Delete
688
679
if (event .equals (StandardWatchEventKinds .ENTRY_MODIFY )) {
689
- Path destPath = FileChangeDetector .getDestPath (filePath , environment );
690
- Files .copy (filePath , destPath , StandardCopyOption .REPLACE_EXISTING );
680
+ Path destPath = FileChangeDetector .getDestPath (filePath , environment , staticOptions );
681
+ Files .copy (filePath , Objects . requireNonNull ( destPath ) , StandardCopyOption .REPLACE_EXISTING );
691
682
}
692
683
} catch (IOException e ) {
693
684
log .error ("Exception when trying to copy updated file" );
0 commit comments