org.jetbrains.kotlin.frontend and webpack, how to use react-router friendly urls
currently have a nice kotlin react project. React-router is kind of working. I have no problem hitting a url like: http://localhost:8088/#/blogPosts
but if remove the # and try and hit: http://localhost:8088/blogPosts
I end up with:
Mon Nov 19 16:48:31 EST 2018
There was an unexpected error (type=Unauthorized, status=401).
Sorry, You're not authorized to access this resource.
here is my build.gradle on the web portion of the product:
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
apply plugin: 'kotlinx-serialization'
kotlinFrontend {
downloadNodeJsVersion = '10.0.0'
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "16.6.0")
dependency("react-dom", "16.6.0")
dependency("react-router-dom", "4.3.1")
dependency("axios", "0.18.0")
dependency("react-modal", "^3.6.1")
dependency("react-quill", "^1.3.2")
dependency("html-react-parser", "^0.4.7")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
sourceMapEnabled = true
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8080"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.11") { force = true }
compile 'org.jetbrains:kotlin-react-router-dom:4.3.1-pre.59-kotlin-1.3.0'
compile "org.jetbrains:kotlin-react:16.5.2-pre.57-kotlin-1.2.71"
compile "org.jetbrains:kotlin-react-dom:16.4.1-pre.34-kotlin-1.2.50"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
}
I am using spring security on the server portion of the project, but that is only handling: 8080 (I believe)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
class SecurityConfig : WebSecurityConfigurerAdapter() {
@Autowired
internal lateinit var securityService: SecurityService //todo remove internal
@Autowired
private val unauthorizedHandler: JwtAuthenticationEntryPoint? = null
@Bean
fun jwtAuthenticationFilter(): JwtAuthenticationFilter {
return JwtAuthenticationFilter()
}
@Throws(Exception::class)
public override fun configure(authenticationManagerBuilder: AuthenticationManagerBuilder?) {
authenticationManagerBuilder!!
.userDetailsService<SecurityService>(securityService)
.passwordEncoder(passwordEncoder())
}
@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Throws(Exception::class)
override fun authenticationManagerBean(): AuthenticationManager {
return super.authenticationManagerBean()
}
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/secUser/checkUsernameAvailability", "/api/secUser/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.anyRequest()
.authenticated()
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter::class.java)
}
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.allowedOrigins = listOf("*")
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE")
configuration.allowedHeaders = listOf("*")
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", configuration)
return source
}
}
webpack react-router kotlin-js
add a comment |
currently have a nice kotlin react project. React-router is kind of working. I have no problem hitting a url like: http://localhost:8088/#/blogPosts
but if remove the # and try and hit: http://localhost:8088/blogPosts
I end up with:
Mon Nov 19 16:48:31 EST 2018
There was an unexpected error (type=Unauthorized, status=401).
Sorry, You're not authorized to access this resource.
here is my build.gradle on the web portion of the product:
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
apply plugin: 'kotlinx-serialization'
kotlinFrontend {
downloadNodeJsVersion = '10.0.0'
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "16.6.0")
dependency("react-dom", "16.6.0")
dependency("react-router-dom", "4.3.1")
dependency("axios", "0.18.0")
dependency("react-modal", "^3.6.1")
dependency("react-quill", "^1.3.2")
dependency("html-react-parser", "^0.4.7")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
sourceMapEnabled = true
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8080"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.11") { force = true }
compile 'org.jetbrains:kotlin-react-router-dom:4.3.1-pre.59-kotlin-1.3.0'
compile "org.jetbrains:kotlin-react:16.5.2-pre.57-kotlin-1.2.71"
compile "org.jetbrains:kotlin-react-dom:16.4.1-pre.34-kotlin-1.2.50"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
}
I am using spring security on the server portion of the project, but that is only handling: 8080 (I believe)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
class SecurityConfig : WebSecurityConfigurerAdapter() {
@Autowired
internal lateinit var securityService: SecurityService //todo remove internal
@Autowired
private val unauthorizedHandler: JwtAuthenticationEntryPoint? = null
@Bean
fun jwtAuthenticationFilter(): JwtAuthenticationFilter {
return JwtAuthenticationFilter()
}
@Throws(Exception::class)
public override fun configure(authenticationManagerBuilder: AuthenticationManagerBuilder?) {
authenticationManagerBuilder!!
.userDetailsService<SecurityService>(securityService)
.passwordEncoder(passwordEncoder())
}
@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Throws(Exception::class)
override fun authenticationManagerBean(): AuthenticationManager {
return super.authenticationManagerBean()
}
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/secUser/checkUsernameAvailability", "/api/secUser/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.anyRequest()
.authenticated()
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter::class.java)
}
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.allowedOrigins = listOf("*")
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE")
configuration.allowedHeaders = listOf("*")
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", configuration)
return source
}
}
webpack react-router kotlin-js
add a comment |
currently have a nice kotlin react project. React-router is kind of working. I have no problem hitting a url like: http://localhost:8088/#/blogPosts
but if remove the # and try and hit: http://localhost:8088/blogPosts
I end up with:
Mon Nov 19 16:48:31 EST 2018
There was an unexpected error (type=Unauthorized, status=401).
Sorry, You're not authorized to access this resource.
here is my build.gradle on the web portion of the product:
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
apply plugin: 'kotlinx-serialization'
kotlinFrontend {
downloadNodeJsVersion = '10.0.0'
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "16.6.0")
dependency("react-dom", "16.6.0")
dependency("react-router-dom", "4.3.1")
dependency("axios", "0.18.0")
dependency("react-modal", "^3.6.1")
dependency("react-quill", "^1.3.2")
dependency("html-react-parser", "^0.4.7")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
sourceMapEnabled = true
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8080"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.11") { force = true }
compile 'org.jetbrains:kotlin-react-router-dom:4.3.1-pre.59-kotlin-1.3.0'
compile "org.jetbrains:kotlin-react:16.5.2-pre.57-kotlin-1.2.71"
compile "org.jetbrains:kotlin-react-dom:16.4.1-pre.34-kotlin-1.2.50"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
}
I am using spring security on the server portion of the project, but that is only handling: 8080 (I believe)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
class SecurityConfig : WebSecurityConfigurerAdapter() {
@Autowired
internal lateinit var securityService: SecurityService //todo remove internal
@Autowired
private val unauthorizedHandler: JwtAuthenticationEntryPoint? = null
@Bean
fun jwtAuthenticationFilter(): JwtAuthenticationFilter {
return JwtAuthenticationFilter()
}
@Throws(Exception::class)
public override fun configure(authenticationManagerBuilder: AuthenticationManagerBuilder?) {
authenticationManagerBuilder!!
.userDetailsService<SecurityService>(securityService)
.passwordEncoder(passwordEncoder())
}
@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Throws(Exception::class)
override fun authenticationManagerBean(): AuthenticationManager {
return super.authenticationManagerBean()
}
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/secUser/checkUsernameAvailability", "/api/secUser/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.anyRequest()
.authenticated()
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter::class.java)
}
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.allowedOrigins = listOf("*")
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE")
configuration.allowedHeaders = listOf("*")
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", configuration)
return source
}
}
webpack react-router kotlin-js
currently have a nice kotlin react project. React-router is kind of working. I have no problem hitting a url like: http://localhost:8088/#/blogPosts
but if remove the # and try and hit: http://localhost:8088/blogPosts
I end up with:
Mon Nov 19 16:48:31 EST 2018
There was an unexpected error (type=Unauthorized, status=401).
Sorry, You're not authorized to access this resource.
here is my build.gradle on the web portion of the product:
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
apply plugin: 'kotlinx-serialization'
kotlinFrontend {
downloadNodeJsVersion = '10.0.0'
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "16.6.0")
dependency("react-dom", "16.6.0")
dependency("react-router-dom", "4.3.1")
dependency("axios", "0.18.0")
dependency("react-modal", "^3.6.1")
dependency("react-quill", "^1.3.2")
dependency("html-react-parser", "^0.4.7")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
sourceMapEnabled = true
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8080"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.11") { force = true }
compile 'org.jetbrains:kotlin-react-router-dom:4.3.1-pre.59-kotlin-1.3.0'
compile "org.jetbrains:kotlin-react:16.5.2-pre.57-kotlin-1.2.71"
compile "org.jetbrains:kotlin-react-dom:16.4.1-pre.34-kotlin-1.2.50"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
}
I am using spring security on the server portion of the project, but that is only handling: 8080 (I believe)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
class SecurityConfig : WebSecurityConfigurerAdapter() {
@Autowired
internal lateinit var securityService: SecurityService //todo remove internal
@Autowired
private val unauthorizedHandler: JwtAuthenticationEntryPoint? = null
@Bean
fun jwtAuthenticationFilter(): JwtAuthenticationFilter {
return JwtAuthenticationFilter()
}
@Throws(Exception::class)
public override fun configure(authenticationManagerBuilder: AuthenticationManagerBuilder?) {
authenticationManagerBuilder!!
.userDetailsService<SecurityService>(securityService)
.passwordEncoder(passwordEncoder())
}
@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Throws(Exception::class)
override fun authenticationManagerBean(): AuthenticationManager {
return super.authenticationManagerBean()
}
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/secUser/checkUsernameAvailability", "/api/secUser/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.anyRequest()
.authenticated()
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter::class.java)
}
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.allowedOrigins = listOf("*")
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE")
configuration.allowedHeaders = listOf("*")
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", configuration)
return source
}
}
webpack react-router kotlin-js
webpack react-router kotlin-js
asked Nov 19 '18 at 21:52
Chris LeggeChris Legge
104413
104413
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383167%2forg-jetbrains-kotlin-frontend-and-webpack-how-to-use-react-router-friendly-urls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383167%2forg-jetbrains-kotlin-frontend-and-webpack-how-to-use-react-router-friendly-urls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown