PageSourceSearch

https://www.jhipster.tech/assets/js/e90365f8.aa829001.js

js jhipster.tech collected 2026-10-01 11:27:00 UTC 4,841 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkjhipster_website=globalThis.webpackChunkjhipster_website||[]).push([[3211],{61282(e,t,s){s.r(t),s.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>l,frontMatter:()=>o,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"tips/tips_enable_cross_origin_requests","title":"Enable cross origin HTTP requests","description":"/!\\\\ This tip is deprecated since JHipster v3.0","source":"@site/docs/tips/006_tips_enable_cross_origin_requests.mdx","sourceDirName":"tips","slug":"/tips/006_tips_enable_cross_origin_requests.html","permalink":"/tips/006_tips_enable_cross_origin_requests.html","draft":false,"unlisted":false,"editUrl":"https://github.com/jhipster/jhipster.github.io/tree/main/docs/tips/006_tips_enable_cross_origin_requests.mdx","tags":[],"version":"current","lastUpdatedAt":1438281600000,"sidebarPosition":6,"frontMatter":{"title":"Enable cross origin HTTP requests","slug":"/tips/006_tips_enable_cross_origin_requests.html","last_update":{"date":"2015-07-30T18:40:00.000Z"}}}');var n=s(74848),r=s(28453);const o={title:"Enable cross origin HTTP requests",slug:"/tips/006_tips_enable_cross_origin_requests.html",last_update:{date:new Date("2015-07-30T18:40:00.000Z")}},c=void 0,a={},d=[{value:"/!\\ This tip is deprecated since JHipster v3.0",id:"-this-tip-is-deprecated-since-jhipster-v30",level:2},{value:"Modify the SecurityConfiguration",id:"modify-the-securityconfiguration",level:2},{value:"Adapt the HTTP response headers",id:"adapt-the-http-response-headers",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",strong:"strong",...(0,r.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.h2,{id:"-this-tip-is-deprecated-since-jhipster-v30",children:"/!\\ This tip is deprecated since JHipster v3.0"}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsxs)(t.strong,{children:["Tip submitted by ",(0,n.jsx)(t.a,{href:"https://github.com/tomcgn",children:"@tomcgn"})]})}),"\n",(0,n.jsxs)(t.p,{children:["You might want to use the nice out-of-the-box API to integrate your application into existing websites.\nOne approach could be to use ",(0,n.jsx)(t.a,{href:"https://github.com/knockout/knockout",children:"Knockout"})," to bind your entities with ease and render the entity on e.g. your blog, being served from your JHipster application."]}),"\n",(0,n.jsx)(t.p,{children:"Two aspects need to be changed in the standard JHipster code in order to use the API from simple HTML/AJAX clients:"}),"\n",(0,n.jsxs)(t.ol,{children:["\n",(0,n.jsxs)(t.li,{children:["Configure the ",(0,n.jsx)(t.code,{children:"SecurityConfiguration"})]}),"\n",(0,n.jsx)(t.li,{children:"Tell the browsers of the users that visit the 3rd party site that uses the API that your app permits the origin of that request."}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"modify-the-securityconfiguration",children:"Modify the SecurityConfiguration"}),"\n",(0,n.jsxs)(t.p,{children:["In method ",(0,n.jsx)(t.code,{children:"SecurityConfiguration.configure(HttpSecurity http)"})," , add new directives as needed in the ",(0,n.jsx)(t.code,{children:".and().authorizeRequests()"})," part, e.g. :"]}),"\n",(0,n.jsx)(t.p,{children:'.antMatchers("/api/_search/meetings/**").permitAll()\n.antMatchers("/api/_search/meetings").permitAll()`'}),"\n",(0,n.jsxs)(t.p,{children:["Of course you can make use of ",(0,n.jsx)(t.code,{children:".hasAuthority()"})," and ",(0,n.jsx)(t.code,{children:".authenticated()"})," to make your thinst-client a bit more dynamic."]}),"\n",(0,n.jsx)(t.h2,{id:"adapt-the-http-response-headers",children:"Adapt the HTTP response headers"}),"\n",(0,n.jsxs)(t.p,{children:["You need to add the following directives to the ",(0,n.jsx)(t.code,{children:"CsrfCookieGeneratorFilter"})," :"]}),"\n",(0,n.jsxs)(t.p,{children:["In method ",(0,n.jsx)(t.code,{children:"doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException"})]}),"\n",(0,n.jsx)(t.p,{children:'response.addHeader("Access-Control-Allow-Origin", "*");\nresponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
1\nresponse.setHeader("Access-Control-Max-Age", "86400"); // 24 Hours\nresponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, x-auth-token");'})]})}function l(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},28453(e,t,s){s.d(t,{R:()=>o,x:()=>c});var i=s(96540);const n={},r=i.createContext(n);function o(e){const t=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:o(e.components),i.createElement(r.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.