mirror of
https://github.com/JonasunderscoreJones/McWebserver.git
synced 2025-10-23 03:19:19 +02:00
added example files on first launch
This commit is contained in:
parent
796fa6a23b
commit
e0b53f93ae
3 changed files with 30 additions and 0 deletions
|
@ -2,6 +2,7 @@ package me.jonasjones.mcwebserver;
|
||||||
|
|
||||||
import com.roxstudio.utils.CUrl;
|
import com.roxstudio.utils.CUrl;
|
||||||
import me.jonasjones.mcwebserver.config.ModConfigs;
|
import me.jonasjones.mcwebserver.config.ModConfigs;
|
||||||
|
import me.jonasjones.mcwebserver.web.HttpServer;
|
||||||
import me.jonasjones.mcwebserver.web.api.v1.ApiHandler;
|
import me.jonasjones.mcwebserver.web.api.v1.ApiHandler;
|
||||||
import me.jonasjones.mcwebserver.web.ServerHandler;
|
import me.jonasjones.mcwebserver.web.ServerHandler;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
@ -19,6 +20,7 @@ public class McWebserver implements ModInitializer {
|
||||||
public static String MOD_ID = "mcwebserver";
|
public static String MOD_ID = "mcwebserver";
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
public static final Logger VERBOSELOGGER = LoggerFactory.getLogger(MOD_ID + " - VERBOSE LOGGER");
|
public static final Logger VERBOSELOGGER = LoggerFactory.getLogger(MOD_ID + " - VERBOSE LOGGER");
|
||||||
|
public static Boolean ISFIRSTSTART = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
@ -27,6 +29,12 @@ public class McWebserver implements ModInitializer {
|
||||||
ModConfigs.registerConfigs();
|
ModConfigs.registerConfigs();
|
||||||
LOGGER.info("McWebserver initialized!");
|
LOGGER.info("McWebserver initialized!");
|
||||||
|
|
||||||
|
if (ISFIRSTSTART) {
|
||||||
|
LOGGER.info("");
|
||||||
|
ServerHandler.createServerDir();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (SERVER_API_ENABLED) {
|
if (SERVER_API_ENABLED) {
|
||||||
//start collecting api info
|
//start collecting api info
|
||||||
ApiHandler.startHandler();
|
ApiHandler.startHandler();
|
||||||
|
|
|
@ -138,6 +138,7 @@ public class SimpleConfig {
|
||||||
String identifier = "Config '" + request.filename + "'";
|
String identifier = "Config '" + request.filename + "'";
|
||||||
|
|
||||||
if (!request.file.exists()) {
|
if (!request.file.exists()) {
|
||||||
|
McWebserver.ISFIRSTSTART = true;
|
||||||
McWebserver.LOGGER.info(identifier + " is missing, generating default one...");
|
McWebserver.LOGGER.info(identifier + " is missing, generating default one...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,8 +3,10 @@ package me.jonasjones.mcwebserver.web;
|
||||||
|
|
||||||
import com.roxstudio.utils.CUrl;
|
import com.roxstudio.utils.CUrl;
|
||||||
import me.jonasjones.mcwebserver.config.ModConfigs;
|
import me.jonasjones.mcwebserver.config.ModConfigs;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static me.jonasjones.mcwebserver.McWebserver.LOGGER;
|
import static me.jonasjones.mcwebserver.McWebserver.LOGGER;
|
||||||
|
@ -59,4 +61,23 @@ public class ServerHandler implements Runnable {
|
||||||
LOGGER.info("Webserver disabled in the config file.");
|
LOGGER.info("Webserver disabled in the config file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createServerDir() {
|
||||||
|
// create server dir as specified in the config WEB_ROOT
|
||||||
|
Path path = FabricLoader.getInstance().getGameDir();
|
||||||
|
Path webroot = path.resolve(ModConfigs.WEB_ROOT);
|
||||||
|
webroot.toFile().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createExampleFiles() {
|
||||||
|
// create example files
|
||||||
|
Path path = FabricLoader.getInstance().getGameDir();
|
||||||
|
Path webroot = path.resolve(ModConfigs.WEB_ROOT);
|
||||||
|
Path index = webroot.resolve(ModConfigs.WEB_FILE_ROOT);
|
||||||
|
Path notsupported = webroot.resolve(ModConfigs.WEB_FILE_NOSUPPORT);
|
||||||
|
Path notfound = webroot.resolve(ModConfigs.WEB_FILE_404);
|
||||||
|
index.toFile().mkdirs();
|
||||||
|
notsupported.toFile().mkdirs();
|
||||||
|
notfound.toFile().mkdirs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue