0

I am trying to serve an Angular app using spring boot/thymeleaf. This is what my class looks like that sends html/css/javascript:

@Controller
public class ResourceProvider {
    
    @RequestMapping(method = RequestMethod.GET, value = "/")
    public String root() {
        
        return "index";
    }
    
    @RequestMapping(method = RequestMethod.GET, value = "/{css}.css")
    public String css(@PathVariable(value = "css") String css, Model model) {

        return css + ".css";
    }
    
    @RequestMapping(method = RequestMethod.GET, value = "/{js}.js")
    public String js(@PathVariable(value = "js") String js, Model model) {
        
        return js + ".js";
    }
}

All of the files are found fine. But when index.html requests the javascript files (main and polyfills in particular), Thymeleaf throws a parse error: Network requests

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "Zone_symbol_prefix||"" (template: "polyfills.718fa2660ef118dd.js" - line 1, col 89)

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "source";let xi;function Tr(t){const e=xi;return xi=t,e}function TC(t,e=x.Default){if(void 0===xi)throw new D(-203,!1);return null===xi?Ah(t,void 0,e):xi.get(t,e&x.Optional?null:void 0,e)}function C(t,e=x.Default){return(function CC(){return Vl}()||TC)(O(t),e)}function G(t,e=x.Default){return C(t,ho(e))}function ho(t){return typeof t>"u"||"number"==typeof t?t:0|(t.optional&&8)|(t.host&&1)|(t.self&&2)|(t.skipSelf&&4)}function zl(t){const e=[];for(let n=0;n<t.length;n++){const r=O(t[n]);if(Array.isArray(r)){if(0===r.length)throw new D(900,!1);let i,s=x.Default;for(let o=0;o<r.length;o++){const a=r[o],l=MC(a);"number"==typeof l?-1===l?i=a.token:s|=l:i=a}e.push(C(i,s))}else e.push(C(r))}return e}function Fi(t,e){return t[Hl]=e,t.prototype[Hl]=e,t}function MC(t){return t[Hl]}function Fn(t){return{toString:t}.toString()}var At=(()=>((At=At||{})[At.OnPush=0]="OnPush",At[At.Default=1]="Default",At))(),Rt=(()=>{return(t=Rt||(Rt={}))[t.Emulated=0]="Emulated",t[t.None=2]="None",t[t.ShadowDom=3]="ShadowDom",Rt;var t})();const un={},X=[],po=ne({ɵcmp:ne}),Gl=ne({ɵdir:ne}),ql=ne({ɵpipe:ne}),Ph=ne({ɵmod:ne}),cn=ne({ɵfac:ne}),ki=ne({" (template: "main.b51697c6f79772d3.js" - line 1, col 89)

Is there a way to just send the javascript files without Thymeleaf processing them? I have no variables that need to be evaluated in these files, I just need them sent to the client.

Thanks.

Cole White
  • 43
  • 5

1 Answers1

1

So the answer was to simply move all of the javascript and css to the /static folder rather than /templates because Thymeleaf was trying to parse the javascript as HTML, which led to an error obviously. So the new resource provider class is

@Controller
public class ResourceProvider {
    
    @RequestMapping(method = RequestMethod.GET, value = "/")
    public String root() {
        
        return "index";
    }
}
Cole White
  • 43
  • 5