Add initial json-server support

This commit is contained in:
Aleksey Filippov 2024-10-23 16:01:04 +04:00
parent 55c7a7a9f9
commit 8bcb15a949
5 changed files with 1041 additions and 46 deletions

14
db.json Normal file
View File

@ -0,0 +1,14 @@
{
"posts": [{ "id": 1, "title": "json-server", "author": "typicode" }],
"comments": [{ "id": 1, "body": "some comment", "postId": 1 }],
"profile": { "name": "typicode" },
"students": [
{ "id": 1, "last_name": "Ivanov", "first_name": "Ivan", "bdate": "01.01.1999", "groupId": 1 },
{ "id": 2, "last_name": "Petrov", "first_name": "Petr", "bdate": "12.12.2000", "groupId": 1 },
{ "id": 3, "last_name": "Sidorov", "first_name": "Sidr", "bdate": "12.12.2000", "groupId": 2 }
],
"groups": [
{ "id": 1, "name": "SomeGroup-11" },
{ "id": 2, "name": "SomeGroup-12" }
]
}

View File

@ -30,6 +30,7 @@ function myBanner(root) {
const LAST_INDEX = banners.length - 1; const LAST_INDEX = banners.length - 1;
// Получить сведения о баннере для показа и его настройках // Получить сведения о баннере для показа и его настройках
// function getBannerConfig() {
const getBannerConfig = () => { const getBannerConfig = () => {
// Получить текущий баннер // Получить текущий баннер
const currentElement = banners.find((banner) => banner.classList.contains("active")); const currentElement = banners.find((banner) => banner.classList.contains("active"));

1009
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,11 @@
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"start": "vite", "start": "npm-run-all --parallel fake-back vite",
"vite": "vite",
"serve": "http-server -p 3000 ./dist/", "serve": "http-server -p 3000 ./dist/",
"build": "vite build", "build": "vite build",
"fake-back": "json-server -p 3001 --watch db.json",
"prod": "npm-run-all build serve", "prod": "npm-run-all build serve",
"lint": "eslint . --ext js --report-unused-disable-directives --max-warnings 0" "lint": "eslint . --ext js --report-unused-disable-directives --max-warnings 0"
}, },
@ -15,6 +17,7 @@
}, },
"devDependencies": { "devDependencies": {
"http-server": "14.1.1", "http-server": "14.1.1",
"json-server": "1.0.0-beta.3",
"vite": "5.4.8", "vite": "5.4.8",
"npm-run-all": "4.1.5", "npm-run-all": "4.1.5",
"eslint": "8.57.1", "eslint": "8.57.1",

View File

@ -35,57 +35,25 @@
</div> </div>
</nav> </nav>
</header> </header>
<main class="container-fluid p-3"> <main id="students" class="container-fluid p-3">
</main> </main>
<footer class="footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center"> <footer class="footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
Автор, 2022 Автор, 2022
</footer> </footer>
<script type="module"> <script type="module">
function someFunc() { const getPosts = async () => {
return "world!"; const students = document.getElementById("students");
} const response = await fetch("http://localhost:3001/students?_embed=group");
const data = await response.json();
data.forEach(element => {
students.innerHTML += `<p>${element.last_name} - ${element.group.name}</p>`;
});
console.log(data);
};
const someFunc2 = function () { document.addEventListener("DOMContentLoaded", () => {
return "asdasd"; getPosts();
} });
const someFunc3 = () => "asdasd111";
const someFunc4 = (x, y) => x * y;
const TEST = `asdasd
asdasdasd
asdasdasd`;
const manufacturer = "lada";
const car = {
manufacturer,
speed: 10,
color: "red",
price: 1000.2,
print: () => `Color is`,
}
let x = "hello!";
console.log(x, someFunc(), someFunc2(), someFunc3(), someFunc4(3, 4));
x = 3;
console.log(`value is ${x} ${x * 2} price ${car.price}`, TEST, car, car.print());
let { speed, color, price } = car;
console.log(speed, color, price);
var arr = [1, 'asd', 'asd', false];
console.log(arr);
let arr1 = [1, 2, 3, 4];
let arr2 = ['a', 'b', 'c'];
let arr3 = [arr1, arr2];
console.log(arr3);
let func = (a, b, c, d) => a + b + c + d
console.log(func(...arr1))
</script> </script>
</body> </body>