Generator-jhipster: Serve static content from folder outside of project

Created on 27 Jul 2016  Â·  11Comments  Â·  Source: jhipster/generator-jhipster

Overview of the issue

I would like to serve static assets – in this case images – from a folder outside of the project in addition to the default front-end generated by JHipster. As of default JHipster seems to serve static assets from one directory out of two depending on environment, as configured in main/java/config/WebConfigurer.java. I would like to point /public/** to a folder in my home catalogue but keep the /** mapping for the Angular front-end.

In general Spring projects you seem to be able to add other sources for static assets by extending WebMvcConfigurerAdapter and override the addResourceHandlers method, but that doesn't seem to have an effect in my case.

Motivation for or Use Case

Uploaded images such as avatars for users are placed in a folder outside of the project, I would like to be able to serve them from there using a url prefix such as "public/".

JHipster Version(s)

Im currently using JHipster Generator v3.4.2.

JHipster configuration
{
  "generator-jhipster": {
    "jhipsterVersion": "3.4.2",
    "baseName": "pixicloud",
    "packageName": "se.pixilab.pixicloud",
    "packageFolder": "se/pixilab/pixicloud",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": "no",
    "websocket": "spring-websocket",
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": "elasticsearch",
    "buildTool": "gradle",
    "enableSocialSignIn": true,
    "jwtSecretKey": "...",
    "useSass": false,
    "applicationType": "monolith",
    "testFrameworks": [
      "gatling"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en",
      "sv"
    ]
  }
}
Browsers and Operating System

I'm on Mac OS El Capitan.

All 11 comments

Your use case is not following the "12 factors", as well as the usual J2EE guidelines (no resources outside the WAR), so I'm against this in the standard app.

Please take this to stack over

Stack overflow i meant

I will take it further on stack overflow but I think I've solved by adding an additional servlet serving the static content from this other folder. However thank you for the reply.

But that's a good use case, I'll answer you when I'm back from holidays

If you have a solution you could consider writing a tip for
https://jhipster.github.io/tips/

2016-07-28 9:15 GMT+02:00 Max Fahl [email protected]:

I will take it further stack overflow but I think I've solved by adding an
additional servlet serving the static content from this other folder.
However thank you for the reply.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/3892#issuecomment-235817976,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAMaiU6g_UZBYBJMk1bU8XExaMRRawyGks5qaFcLgaJpZM4JV478
.

Any new suggestions/tips regarding this issue? Thanks.

@vicgrad Please try to put your question on stackoverfolow instead of adding comments to a long time closed ticket. In the meanwhile a lot have been change and it can be that you will get a better answer there. Other option is also the gitter chanel.

You might want to have a look at http://www.jhipster.tech/separating-front-end-and-api/ but yes StackOverflow is your friend for this, as it is not a bug

If you create the back only code using skip server then you can create a folder src/main/resources/static . You can then put your frontend code in src/main/resources/static and then for example your index.html file will end up in this directory. It will then be served by jhipster when you start it.

target/myapplication-0.0.1-SNAPSHOT/WEB-INF/classes/static/index.html

Your use case is not following the "12 factors", as well as the usual J2EE guidelines (no resources outside the WAR), so I'm against this in the standard app.

J2EE guidelines didn't talk about the application data images which are dynamic , it says only resource images like logo or some icons which are limited . its better to save content images in local system and map resource from local

for example : sample e commerce application need image to be uploaded and even application restart it should hold the images

for this copy below in your Jhipster app java file

~java
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/mmimages/**")
.addResourceLocations("file:/Users/manikumar/temp/")
.setCachePeriod(0);
}
}
~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chegola picture chegola  Â·  4Comments

pascalgrimaud picture pascalgrimaud  Â·  3Comments

marcelinobadin picture marcelinobadin  Â·  3Comments

tomj0101 picture tomj0101  Â·  3Comments

RizziCR picture RizziCR  Â·  3Comments