Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
coastal-tep
interactive-application-service
Commits
39941c39
Commit
39941c39
authored
7 years ago
by
Christoph Holter
Browse files
Options
Download
Email Patches
Plain Diff
add complete WebConfig
parent
3d6c4a4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
2 deletions
+63
-2
backend/src/main/java/cc/catalysts/config/FallbackPathResourceResolver.java
...ava/cc/catalysts/config/FallbackPathResourceResolver.java
+37
-0
backend/src/main/java/cc/catalysts/config/WebConfig.java
backend/src/main/java/cc/catalysts/config/WebConfig.java
+26
-2
No files found.
backend/src/main/java/cc/catalysts/config/FallbackPathResourceResolver.java
0 → 100644
View file @
39941c39
package
cc.catalysts.config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.core.io.Resource
;
import
org.springframework.web.servlet.resource.PathResourceResolver
;
import
java.io.IOException
;
/**
* Created by alexander.navratil@catalysts.cc
* Class responsible for serving static files.
*/
public
class
FallbackPathResourceResolver
extends
PathResourceResolver
{
private
ServerProperties
serverProperties
;
@Autowired
public
FallbackPathResourceResolver
(
ServerProperties
serverProperties
)
{
this
.
serverProperties
=
serverProperties
;
}
@Override
protected
Resource
getResource
(
String
resourcePath
,
Resource
location
)
throws
IOException
{
Resource
res
=
super
.
getResource
(
resourcePath
,
location
);
if
(
serverProperties
.
getContextPath
()
!=
null
&&
resourcePath
.
startsWith
(
serverProperties
.
getContextPath
()))
{
resourcePath
=
resourcePath
.
substring
(
serverProperties
.
getContextPath
().
length
());
}
if
(
res
==
null
){
if
(
resourcePath
.
endsWith
(
".js"
)){
String
file
=
resourcePath
.
substring
(
resourcePath
.
lastIndexOf
(
'/'
)+
1
);
return
super
.
getResource
(
"/static/"
+
file
,
location
);
}
return
super
.
getResource
(
"index.html"
,
location
);
}
return
res
;
}
}
This diff is collapsed.
Click to expand it.
backend/src/main/java/cc/catalysts/config/WebConfig.java
View file @
39941c39
package
cc.catalysts.config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.PathMatchConfigurer
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.util.UrlPathHelper
;
/**
* Created by alexander.navratil@catalysts.cc
* This class configures: Swagger Documentation, create initial ctep user, allow encoded slashes in PathVariables
*/
@Configuration
public
class
WebConfig
extends
WebMvcConfigurerAdapter
{
private
ServerProperties
serverProperties
;
private
AppConfig
appConfig
;
public
WebConfig
(
AppConfig
appConfig
)
{
@Autowired
public
WebConfig
(
ServerProperties
serverProperties
,
AppConfig
appConfig
)
{
this
.
serverProperties
=
serverProperties
;
this
.
appConfig
=
appConfig
;
}
...
...
@@ -18,6 +28,20 @@ public class WebConfig extends WebMvcConfigurerAdapter {
registry
.
addResourceHandler
(
"/ext/**"
)
.
addResourceLocations
(
"file://"
+
appConfig
.
getExternalStaticLocation
())
.
resourceChain
(
true
);
registry
.
addResourceHandler
(
"/**"
)
.
addResourceLocations
(
"classpath:/static/"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/"
)
.
resourceChain
(
true
)
.
addResolver
(
new
FallbackPathResourceResolver
(
serverProperties
));
}
/**
* Workaround for allowing encoded slashes in PathVariables
*/
@Override
public
void
configurePathMatch
(
PathMatchConfigurer
configurer
)
{
UrlPathHelper
urlPathHelper
=
new
UrlPathHelper
();
urlPathHelper
.
setUrlDecode
(
false
);
configurer
.
setUrlPathHelper
(
urlPathHelper
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment