R
Railway11mo ago
domasch

Spring boot up and running after deployment but can't access via http

//.
15 Replies
Percy
Percy11mo ago
Project ID: 6740a982-9486-4b46-9424-8207b2348680
domasch
domaschOP11mo ago
6740a982-9486-4b46-9424-8207b2348680 (Yes I know the passwords are not secure it's just for. auni project) Okay I've now fixed this issue by deleting adn recreating a database (forwhatever reason this fixed it) but now I see my service is up and running in deploy logs but I can't access it via http even tho I created a public domain for it
Lelebees
Lelebees11mo ago
Does the spring boot deployment have a PORT variable in it's environment variables on railway?
domasch
domaschOP11mo ago
# Start with a base image containing Java runtime
FROM openjdk:17-jdk-slim AS build

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
# Add the application's jar to the container
COPY ./target/*.jar app.jar

COPY lvas.txt lvas.txt
COPY bachelor_shorthands.txt bachelor_shorthands.txt
COPY master_softwareengineering_shorthands.txt master_softwareengineering_shorthands.txt
COPY rooms.txt rooms.txt

# Run the jar file
ENTRYPOINT ["java", "-jar","/app.jar"]
# Start with a base image containing Java runtime
FROM openjdk:17-jdk-slim AS build

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
# Add the application's jar to the container
COPY ./target/*.jar app.jar

COPY lvas.txt lvas.txt
COPY bachelor_shorthands.txt bachelor_shorthands.txt
COPY master_softwareengineering_shorthands.txt master_softwareengineering_shorthands.txt
COPY rooms.txt rooms.txt

# Run the jar file
ENTRYPOINT ["java", "-jar","/app.jar"]
this is my Dockerfile beware the copies but do I still need to set the ENV PORT=8080?
Lelebees
Lelebees11mo ago
Either that or the http port you've got from exposing the app
domasch
domaschOP11mo ago
will try adn report back thx redeploying with var just broke it becasue of database already exists .... now I removed the dtabase config in spring taht creates the databse if not existatn and NOW IT WORKS THANKS ❤️ Do you think it is possible to use ddl auto mode to create the tables or is taht a bad idea>?
Lelebees
Lelebees11mo ago
If you're using hibernate, you can set it to automatically create or update your tables for you I've got my own spring instance running with that setting and encountered no issues
domasch
domaschOP11mo ago
I though so too
jpa: # Set this property to true if you want to see the executed queries
show-sql: false
hibernate:
ddl-auto: update
# Allows to fetch lazy properties outside of the original transaction. Although this sounds helpful, the property
# is disabled since it breaks the principle of least astonishment and leads to bad performance. To learn more,
# follow this link: https://bit.ly/2LaX9ku
open-in-view: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
jpa: # Set this property to true if you want to see the executed queries
show-sql: false
hibernate:
ddl-auto: update
# Allows to fetch lazy properties outside of the original transaction. Although this sounds helpful, the property
# is disabled since it breaks the principle of least astonishment and leads to bad performance. To learn more,
# follow this link: https://bit.ly/2LaX9ku
open-in-view: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
that should do the trick right?
Lelebees
Lelebees11mo ago
Yes, i think that is correct Don't forget to update your database password!
domasch
domaschOP11mo ago
haha will do but for now I wanna get it working // interesting I tried it out locally now to access
package at.ac.tuwien.sepr.groupphase.backend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedMethods(CorsConfiguration.ALL)
.allowedHeaders(CorsConfiguration.ALL)
.allowedOriginPatterns(CorsConfiguration.ALL);
}
}
package at.ac.tuwien.sepr.groupphase.backend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedMethods(CorsConfiguration.ALL)
.allowedHeaders(CorsConfiguration.ALL)
.allowedOriginPatterns(CorsConfiguration.ALL);
}
}
I know insecurenagain but I think I'm already allowing all remotes in my spring application how can CORS still be an isseu?
Lelebees
Lelebees11mo ago
When sending data from your local machine CORS usually steps in. Try sending a request through a service like postman
Lelebees
Lelebees11mo ago
This is the response i got from postman by sending a request to your api, no cors error!
No description
domasch
domaschOP11mo ago
Yes I tried that alrady from http file and works like a charm idk what's going on tbh also tried changing proxyconf inn angular When I deploy the frontne dI get invalid host header any ideas?
Lelebees
Lelebees11mo ago
Unfortunately not. Perhaps someone else here does though
domasch
domaschOP11mo ago
ah fixed it with --disable-host-check bt cors issue still here hmm
export const environment = {
production: false,
backendUrl: 'https://myservice.railway.internal/api/v1'
// backendUrl: 'http://localhost:8080/api/v1'
};
export const environment = {
production: false,
backendUrl: 'https://myservice.railway.internal/api/v1'
// backendUrl: 'http://localhost:8080/api/v1'
};
if using internal url do I need to change anything else? Request URL: https://myservice.up.railway.app/tiss-time-myservice.railway.internal/api/v1/register Request Method: POST this changed the request url to this for some reason
{
"/api": {
"target": "https://myservice.railway.internal",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": "/api/v1"
}
}
}
{
"/api": {
"target": "https://myservice.railway.internal",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": "/api/v1"
}
}
}
this is my proxyconf
Want results from more Discord servers?
Add your server