From c3ce1336cb5fabee614d34deec73cc8655d60249 Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Tue, 7 Feb 2023 10:52:36 +0400 Subject: [PATCH] Added frontend --- frontend/index.html | 42 +++++++++++++++++ frontend/index.js | 12 +++++ frontend/node_modules/fs/README.md | 9 ++++ frontend/node_modules/fs/package.json | 46 +++++++++++++++++++ frontend/node_modules/http/README.md | 9 ++++ frontend/node_modules/http/package.json | 39 ++++++++++++++++ frontend/package-lock.json | 18 ++++++++ frontend/package.json | 15 ++++++ .../java/np/something/WebConfiguration.java | 13 ++++++ .../controllers/GreetingController.java | 13 ------ .../something/controllers/MathController.java | 41 +++++++++++++++++ 11 files changed, 244 insertions(+), 13 deletions(-) create mode 100644 frontend/index.html create mode 100644 frontend/index.js create mode 100644 frontend/node_modules/fs/README.md create mode 100644 frontend/node_modules/fs/package.json create mode 100644 frontend/node_modules/http/README.md create mode 100644 frontend/node_modules/http/package.json create mode 100644 frontend/package-lock.json create mode 100644 frontend/package.json create mode 100644 src/main/java/np/something/WebConfiguration.java delete mode 100644 src/main/java/np/something/controllers/GreetingController.java create mode 100644 src/main/java/np/something/controllers/MathController.java diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..cae03df --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,42 @@ + + + + + Калькулятор + + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+

+
+
+ + + + \ No newline at end of file diff --git a/frontend/index.js b/frontend/index.js new file mode 100644 index 0000000..69dc105 --- /dev/null +++ b/frontend/index.js @@ -0,0 +1,12 @@ +const fs = require('fs') +const http = require('http') + +const requestListener = async function (req, res) { + res.writeHead(200); + fs.readFile('index.html', (err, data) => { + res.end(data); + }); +}; + +const server = http.createServer(requestListener) +server.listen(5050) \ No newline at end of file diff --git a/frontend/node_modules/fs/README.md b/frontend/node_modules/fs/README.md new file mode 100644 index 0000000..5e9a74c --- /dev/null +++ b/frontend/node_modules/fs/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/frontend/node_modules/fs/package.json b/frontend/node_modules/fs/package.json new file mode 100644 index 0000000..e92ec55 --- /dev/null +++ b/frontend/node_modules/fs/package.json @@ -0,0 +1,46 @@ +{ + "_from": "fs", + "_id": "fs@0.0.1-security", + "_inBundle": false, + "_integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==", + "_location": "/fs", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "fs", + "name": "fs", + "escapedName": "fs", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "_shasum": "8a7bd37186b6dddf3813f23858b57ecaaf5e41d4", + "_spec": "fs", + "_where": "C:\\Users\\user\\Desktop\\something\\frontend", + "author": "", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.", + "homepage": "https://github.com/npm/security-holder#readme", + "keywords": [], + "license": "ISC", + "main": "index.js", + "name": "fs", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "version": "0.0.1-security" +} diff --git a/frontend/node_modules/http/README.md b/frontend/node_modules/http/README.md new file mode 100644 index 0000000..5e9a74c --- /dev/null +++ b/frontend/node_modules/http/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/frontend/node_modules/http/package.json b/frontend/node_modules/http/package.json new file mode 100644 index 0000000..cd334ca --- /dev/null +++ b/frontend/node_modules/http/package.json @@ -0,0 +1,39 @@ +{ + "_from": "http", + "_id": "http@0.0.1-security", + "_inBundle": false, + "_integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==", + "_location": "/http", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "http", + "name": "http", + "escapedName": "http", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", + "_shasum": "3aac09129d12dc2747bbce4157afde20ad1f7995", + "_spec": "http", + "_where": "C:\\Users\\user\\Desktop\\something\\frontend", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "security holding package", + "homepage": "https://github.com/npm/security-holder#readme", + "name": "http", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "version": "0.0.1-security" +} diff --git a/frontend/package-lock.json b/frontend/package-lock.json new file mode 100644 index 0000000..fda2a8f --- /dev/null +++ b/frontend/package-lock.json @@ -0,0 +1,18 @@ +{ + "name": "frontend", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, + "http": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", + "integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==" + } + } +} diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..73bed9a --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,15 @@ +{ + "name": "frontend", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "node index.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "fs": "0.0.1-security", + "http": "0.0.1-security" + } +} diff --git a/src/main/java/np/something/WebConfiguration.java b/src/main/java/np/something/WebConfiguration.java new file mode 100644 index 0000000..7b95d8d --- /dev/null +++ b/src/main/java/np/something/WebConfiguration.java @@ -0,0 +1,13 @@ +package np.something; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfiguration implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods("*"); + } +} diff --git a/src/main/java/np/something/controllers/GreetingController.java b/src/main/java/np/something/controllers/GreetingController.java deleted file mode 100644 index 19be9ec..0000000 --- a/src/main/java/np/something/controllers/GreetingController.java +++ /dev/null @@ -1,13 +0,0 @@ -package np.something.controllers; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class GreetingController { - @GetMapping("/greet") - public String greeting(@RequestParam(value = "name", defaultValue = "world") String name) { - return "Hello, " + name + "!"; - } -} diff --git a/src/main/java/np/something/controllers/MathController.java b/src/main/java/np/something/controllers/MathController.java new file mode 100644 index 0000000..2e28fec --- /dev/null +++ b/src/main/java/np/something/controllers/MathController.java @@ -0,0 +1,41 @@ +package np.something.controllers; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MathController { + @GetMapping("/sum") + public int sum( + @RequestParam(value = "num1", defaultValue = "0") int num1, + @RequestParam(value = "num2", defaultValue = "0") int num2 + ) { + + return num1 + num2; + } + + @GetMapping("/sub") + public int sub( + @RequestParam(value = "num1", defaultValue = "0") int num1, + @RequestParam(value = "num2", defaultValue = "0") int num2 + ) { + return num1 - num2; + } + + @GetMapping("/mul") + public int mul( + @RequestParam(value = "num1", defaultValue = "0") int num1, + @RequestParam(value = "num2", defaultValue = "0") int num2 + ) { + return num1 * num2; + } + + @GetMapping("/div") + public int div( + @RequestParam(value = "num1", defaultValue = "0") int num1, + @RequestParam(value = "num2", defaultValue = "0") int num2 + ) { + return num1 / num2; + } +}