Make ports configurable

This commit is contained in:
Steven Tracey 2024-08-07 15:20:29 -04:00
parent 6bf31736e3
commit fe6f88bc62
4 changed files with 19 additions and 39 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/Program Files/Gradle" />
<option name="gradleHome" value="$PROJECT_DIR$/../../../../Program Files/Gradle" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">

View File

@ -4,16 +4,14 @@ plugins {
}
group 'tech.nevets'
version '1.0'
version '1.1.0'
repositories {
mavenCentral()
}
dependencies {
implementation 'io.javalin:javalin:4.6.0'
implementation 'org.slf4j:slf4j-simple:1.7.36'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
implementation 'com.sparkjava:spark-core:2.9.4'
}
shadowJar {

View File

@ -1,44 +1,27 @@
package tech.nevets.beerestapi;
import io.javalin.Javalin;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import static spark.Spark.*;
public class Main {
public static ArrayList<String> urls = new ArrayList<>();
public static List<String> urls = List.of(
"vetlog.jpg",
""
);
public static void main(String[] args) {
getImageUrlList();
Javalin app = Javalin.create().start(8080);
app.get("/bee", ctx -> {
ctx.json("{\"link\": \"https://img.nevets.tech/" + getRandomUrl() + "\"}");
});
}
public static void getImageUrlList() {
String line;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("./image-urls.txt"));
while ((line = in.readLine()) != null) {
urls.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
if (args[0] != null) {
port(Integer.parseInt(args[0]));
} else {
port(8080);
}
get("/bee", (req, res) -> {
return "{\"link\": \"https://img.nevets.tech/" + getRandomUrl() + "\"}";
});
}
public static String getRandomUrl() {