forked from maiora/backend-api
Compare commits
8 Commits
0002343-en
...
main
Author | SHA1 | Date | |
---|---|---|---|
0e061c9eca | |||
7b8eaa6261 | |||
7f6e1fc6cb | |||
8a934dca5b | |||
23733caca9 | |||
b49577804e | |||
8242c78b35 | |||
74570dc330 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -41,3 +41,4 @@ bin/
|
|||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.idea/.name
|
.idea/.name
|
||||||
|
*.log
|
||||||
|
@ -9,6 +9,10 @@ plugins {
|
|||||||
kotlin("plugin.serialization") version "1.9.23" // Aggiungi il plugin di Serialization
|
kotlin("plugin.serialization") version "1.9.23" // Aggiungi il plugin di Serialization
|
||||||
}
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass.set("eu.maiora.ApplicationKt")
|
||||||
|
}
|
||||||
|
|
||||||
group = "org.maiora"
|
group = "org.maiora"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.0-SNAPSHOT"
|
||||||
|
|
||||||
|
@ -9,21 +9,26 @@ import io.ktor.server.engine.*
|
|||||||
import io.ktor.server.netty.*
|
import io.ktor.server.netty.*
|
||||||
import io.ktor.server.plugins.callloging.*
|
import io.ktor.server.plugins.callloging.*
|
||||||
import io.ktor.server.plugins.cors.routing.*
|
import io.ktor.server.plugins.cors.routing.*
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
embeddedServer(Netty, port = 8098, host = "0.0.0.0", module = Application::module)
|
val properties = loadConfig()
|
||||||
.start(wait = true)
|
val port = properties.getProperty("server.port").toInt()
|
||||||
|
embeddedServer(Netty, port = port, host = "0.0.0.0") {
|
||||||
|
module(properties)
|
||||||
|
}.start(wait = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Application.module() {
|
fun Application.module(configFile: Properties) {
|
||||||
val config = ApplicationConfig("application.conf")
|
val config = ApplicationConfig("application.conf")
|
||||||
val dbUrl = config.property("ktor.database.url").getString()
|
val dbUrl = configFile.getProperty("ktor.database.url")
|
||||||
val username = config.property("ktor.database.username").getString()
|
val username = configFile.getProperty("ktor.database.username")
|
||||||
val password = config.property("ktor.database.password").getString()
|
val password = configFile.getProperty("ktor.database.password")
|
||||||
val secret = config.property("ktor.jwt.secret").getString()
|
val secret = config.property("ktor.jwt.secret").getString()
|
||||||
configureDatabases(dbUrl, username, password)
|
configureDatabases(dbUrl, username, password)
|
||||||
configureSecurity(secret)
|
configureSecurity(secret)
|
||||||
configureRouting(dbUrl, username, password)
|
configureRouting()
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
|
|
||||||
install(CallLogging)
|
install(CallLogging)
|
||||||
@ -39,3 +44,10 @@ fun Application.module() {
|
|||||||
allowMethod(HttpMethod.Delete)
|
allowMethod(HttpMethod.Delete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun loadConfig(): Properties {
|
||||||
|
val properties = Properties()
|
||||||
|
val inputStream = FileInputStream("/home/backend_api/config.properties")
|
||||||
|
properties.load(inputStream)
|
||||||
|
return properties
|
||||||
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
package eu.maiora.plugins
|
package eu.maiora.plugins
|
||||||
|
|
||||||
//import eu.maiora.model.LogScriptRepositoryImpl
|
|
||||||
//import eu.maiora.routes.analizzaURLRoute
|
|
||||||
//import eu.maiora.routes.eseguiScriptSQLRoute
|
|
||||||
//import eu.maiora.routes.logScriptRouting
|
|
||||||
import eu.maiora.model.AccountsRepositoryImpl
|
import eu.maiora.model.AccountsRepositoryImpl
|
||||||
import eu.maiora.model.ParametriRepositoryImpl
|
|
||||||
import eu.maiora.routes.auth
|
import eu.maiora.routes.auth
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
//fun Application.configureRouting(dbUrl : String, username : String, password : String, repository : LogScriptRepositoryImpl ) {
|
fun Application.configureRouting() {
|
||||||
fun Application.configureRouting(dbUrl : String, username : String, password : String) {
|
|
||||||
routing {
|
routing {
|
||||||
get("/") {
|
get("/") {
|
||||||
call.respondText("Hello World!")
|
call.respondText("Hello World!")
|
||||||
|
@ -16,7 +16,7 @@ import java.util.*
|
|||||||
|
|
||||||
|
|
||||||
fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
||||||
route("/auth") {
|
route("/api/auth") {
|
||||||
post() {
|
post() {
|
||||||
// Riceve il body della richiesta e lo deserializza in ReceivedResponse
|
// Riceve il body della richiesta e lo deserializza in ReceivedResponse
|
||||||
val receivedResponse = try {
|
val receivedResponse = try {
|
||||||
@ -31,7 +31,7 @@ fun Route.auth(accountsRepository: AccountsRepositoryImpl) {
|
|||||||
logger.info(
|
logger.info(
|
||||||
"param: " +
|
"param: " +
|
||||||
receivedResponse.param
|
receivedResponse.param
|
||||||
);
|
)
|
||||||
|
|
||||||
// Decodifica la stringa da Base64 a oggetto Credentials
|
// Decodifica la stringa da Base64 a oggetto Credentials
|
||||||
val decodedBytes = Base64.getDecoder().decode(receivedResponse.param)
|
val decodedBytes = Base64.getDecoder().decode(receivedResponse.param)
|
||||||
|
@ -1,18 +1,4 @@
|
|||||||
ktor {
|
ktor {
|
||||||
database {
|
|
||||||
; url = "jdbc:postgresql://192.168.20.49:5432/caritas"
|
|
||||||
; username = "caritas"
|
|
||||||
; password = "caritas"
|
|
||||||
; driver = "org.postgresql.Driver"
|
|
||||||
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
|
|
||||||
url = "jdbc:sqlserver://192.168.20.45;databaseName=EP_FAER;integratedSecurity=false;encrypt=true;trustServerCertificate=true;"
|
|
||||||
username = "SA"
|
|
||||||
password = "I5fz9l1a"
|
|
||||||
;driver = "oracle.jdbc.OracleDriver"
|
|
||||||
;url = "jdbc:oracle:thin:@//192.168.20.101:1521/SIR"
|
|
||||||
;username = "EP_DONORIONE"
|
|
||||||
;password = "ep_donorione"
|
|
||||||
}
|
|
||||||
jwt {
|
jwt {
|
||||||
# secret per JWT generato partendo dalla stringa '?Backend_API*06022025!' codificato in Base64
|
# secret per JWT generato partendo dalla stringa '?Backend_API*06022025!' codificato in Base64
|
||||||
secret = "P0JhY2tlbmRfQVBJKjA2MDIyMDI1IQ=="
|
secret = "P0JhY2tlbmRfQVBJKjA2MDIyMDI1IQ=="
|
||||||
|
43
src/main/resources/logback.xml
Normal file
43
src/main/resources/logback.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<configuration>
|
||||||
|
|
||||||
|
<!-- Appender per la console -->
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Appender per il file di log con rotazione basata su tempo e dimensione -->
|
||||||
|
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>./log/logFile.log</file> <!-- File di log principale -->
|
||||||
|
<append>true</append>
|
||||||
|
|
||||||
|
<!-- RollingPolicy per dimensione e tempo -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
|
<!-- Pattern per il nome dei file ruotati: include la data -->
|
||||||
|
<FileNamePattern>./log/logFile.%d{yyyy-MM-dd}.%i.log</FileNamePattern> <!-- %i è il numero di file generato -->
|
||||||
|
|
||||||
|
<!-- Limita la dimensione del file a 100MB -->
|
||||||
|
<maxFileSize>100MB</maxFileSize> <!-- Ruota il file quando raggiunge 100MB -->
|
||||||
|
|
||||||
|
<!-- Conserva i log per due settimane -->
|
||||||
|
<maxHistory>15</maxHistory> <!-- Limita a 15 giorni i log archiviati -->
|
||||||
|
|
||||||
|
<!-- Limita la dimensione totale dei file di log a 5GB -->
|
||||||
|
<totalSizeCap>5GB</totalSizeCap>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Configurazione del livello di log -->
|
||||||
|
<root level="DEBUG">
|
||||||
|
<appender-ref ref="ROLLING_FILE"/>
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<logger name="io.netty" level="INFO"/>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue
Block a user