Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# WebProgramming lab work №1


## Quick Start
```bash
docker compose up
```

## Structure
```
├── httpd/ # Директория с конфигурациями веб-серверов и статическими файлами
├── nginx-conf/ # Конфиг веб-сервера для nginx
├── apache-conf/ # Конфиг веб-сервера для apache (! НА ДАННЫЙ МОМЕНТ ОТКЛЮЧЁН !)
├── static/ # Директория с статическими файлами
├── index.html # Основной файл сайта
├── js/ # Js сайта
└── assets/ # Ресурсы сайта
├── Dockerfile-nginx # Dockerfile для Nginx
└── Dockerfile-apache # Dockerfile для Apache (! НА ДАННЫЙ МОМЕНТ ОТКЛЮЧЁН !)
├── server/ # Директория с кодом java-сервера (FastCGI)
├── lib/ # Директория с библиотекой для fastcgi
├── src/ # Исходники
└── Dockerfile # Dockerfile для fastcgi-сервера
└── docs # Дополнительная документация
```


## TODOs

### Httpd
Expand Down
86 changes: 86 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
openapi: 3.0.0
info:
title: "WebProg Lab1"
version: 0.0.2
description: |
Сервак из говна и палок

Last update: 00:00 15.09.25 by NF-coder
servers:
- url: http://localhost:8080/fcgi/
description: FastCGI API

paths:
/:
get:
summary: Тест попадания в область
tags:
- General
parameters:
- in: query
name: x
required: true
schema:
$ref: "#/components/schemas/x"
- in: query
name: y
required: true
schema:
$ref: "#/components/schemas/y"
- in: query
name: r
required: true
schema:
$ref: "#/components/schemas/r"

responses:
200:
description: Responce with data
content:
application/json:
schema:
type: object
properties:
result:
type: boolean
description: "true if hitted area and false if missed"
example: true
elapsedTimeNs:
type: integer
description: "Time in ns that server spent while handling responce"
example: 12345
default:
description: Error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
x:
type: integer
description: Кордината X
example: 0
y:
type: number
description: Кордината Y
example: 0
r:
type: number
description: Параметр R
example: 2

Error:
type: object
required:
- error
properties:
error:
type: string
description: "Description of error"
example: Some text





Binary file added httpd/static/assets/img/logo.ico
Binary file not shown.
3 changes: 1 addition & 2 deletions httpd/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web lab1</title>
<script src="./js/ajax.js"></script>
<link rel="icon" href="assets/img/logo.ico" type="image/x-icon"/>
<style>
:root {
/* Цветовая палитра в OKLCH */
Expand Down Expand Up @@ -733,9 +734,7 @@ <h3 class="history-title">История введенных данных</h3>

if (X && R && Y) {

// Stub
sendAJAXGETRequest("/fcgi/", {"x": X, "y": Y, "r": R}, (data) => {FFCGIResponceHandler(data, X,Y,R)});
console.log(`Данные отправлены!\nX: ${X}\nY: ${Y}\nR: ${R}`);

// Очищаем форму
this.reset();
Expand Down
9 changes: 8 additions & 1 deletion server/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-jdk-slim AS build
FROM eclipse-temurin:17-jdk-alpine AS build

# copy maven confis
COPY pom.xml mvnw ./
Expand All @@ -14,7 +14,7 @@ RUN ./mvnw dependency:resolve
COPY src src
RUN ./mvnw clean package

FROM openjdk:17-jdk-slim
FROM eclipse-temurin:17-jre-alpine
WORKDIR server
COPY --from=build target/*.jar server-1.0.jar
ENTRYPOINT ["java", "-DFCGI_PORT=55555", "-jar", "server-1.0.jar"]
17 changes: 11 additions & 6 deletions server/src/main/java/org/web1/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.web1;

import com.fastcgi.*;

import java.util.HashMap;
import java.util.function.Function;

Expand All @@ -9,10 +10,11 @@
import org.web1.DTOs.RequestDTO;
import org.web1.checkers.Checker;
import org.web1.checkers.CheckerFunction;
import org.web1.netUtils.JsonBuilder;
import org.web1.netUtils.QueryStringToHashmap;
import org.web1.netUtils.ResponseFactory;
import org.web1.timer.Timer;
import org.web1.utils.mappers.JsonBuilder;
import org.web1.utils.mappers.QueryStringToHashmap;
import org.web1.utils.responce.ResponseFactory;
import org.web1.utils.responce.ResponseStatus;
import org.web1.utils.timer.Timer;

public class Main {
private static final Function<String, HashMap<String,String>> parseQuery = new QueryStringToHashmap();
Expand Down Expand Up @@ -46,13 +48,16 @@ public static void main(String[] args) {
String result = ResponseFactory.create(
new JsonBuilder()
.add("result", checkResult)
.add("elapsedTimeNs", timer.stop())
.add("elapsedTimeNs", timer.stop()),
ResponseStatus.OK
);

System.out.println(result);
} catch (ValidationException e) {
String result = ResponseFactory.create(
new JsonBuilder().add("error", '"'+e.getMessage()+'"')
new JsonBuilder()
.add("error", '"'+e.getMessage()+'"'),
ResponseStatus.BAD_REQUEST
);
System.out.println(result);
}
Expand Down
15 changes: 0 additions & 15 deletions server/src/main/java/org/web1/netUtils/ResponseFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.netUtils;
package org.web1.utils.mappers;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.netUtils;
package org.web1.utils.mappers;

import java.util.HashMap;
import java.util.function.Function;
Expand Down
37 changes: 37 additions & 0 deletions server/src/main/java/org/web1/utils/responce/ResponseFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.web1.utils.responce;

import org.web1.utils.mappers.JsonBuilder;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;

public class ResponseFactory {
private static final String BASE_RESPONSE = """
HTTP/2 %s\r
Status: %s\r
Access-Control-Allow-Origin: *\r
Connection: keep-alive\r
Content-Type: application/json; charset=utf-8\r
Content-Length: %d\r
\r
%s""";

private static final HashMap<ResponseStatus, String> responseStatus = new HashMap<>();

static {
responseStatus.put(ResponseStatus.BAD_REQUEST, "400");
responseStatus.put(ResponseStatus.OK, "200");
}

public static String create(JsonBuilder jsonBuilder, ResponseStatus status) {
String response = jsonBuilder.build();

return String.format(
BASE_RESPONSE,
responseStatus.get(status),
responseStatus.get(status),
response.getBytes(StandardCharsets.UTF_8).length + 1,
response
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.web1.utils.responce;

public enum ResponseStatus {
BAD_REQUEST,
OK
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.timer;
package org.web1.utils.timer;

public class Timer {
long startTime;
Expand Down