generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from moevm/BaseVersion
baseVersion
- Loading branch information
Showing
23 changed files
with
1,754 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PORT=3000 | ||
ARANGO_URL=http://arango:8529 | ||
ARANGO_USER=root | ||
ARANGO_PASSWORD=password | ||
ARANGO_DB=city_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
FROM node:18 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD [ "npm", "start" ] | ||
FROM node:18 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD [ "npm", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require('dotenv').config(); | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); // обработка данных | ||
const { Database } = require('arangojs'); | ||
const path = require('path'); // работа с путями файловой системы | ||
const { importData } = require('./import'); | ||
|
||
var indexRouter = require('./routes/index'); | ||
var usersRouter = require('./routes/users'); | ||
const mainRouter = require("./routes/main"); | ||
|
||
const app = express(); | ||
const port = process.env.PORT || 3000; // по умолчанию порт 3000 | ||
|
||
// Создаем экземпляр базы данных с указанием databaseName | ||
const db = new Database({ | ||
url: process.env.ARANGO_URL || 'http://arango:8529', | ||
databaseName: process.env.ARANGO_DB || 'city_data', | ||
auth: { | ||
username: process.env.ARANGO_USER || 'root', | ||
password: process.env.ARANGO_PASSWORD || 'password' | ||
} | ||
}); | ||
|
||
// Настройка EJS как шаблонизатора | ||
app.set('view engine', 'ejs'); | ||
app.set('views', path.join(__dirname, 'views')); | ||
|
||
// Подключаем парсеры для обработки данных форм | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
// Настройка папки для статических файлов | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/', indexRouter); | ||
app.use('/users', usersRouter); | ||
app.use("/main", mainRouter); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
next(createError(404)); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.render('error'); | ||
}); | ||
|
||
module.exports = app; // чтобы можно было импортировать этот файл | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Запуск сервера | ||
app.listen(port, () => { | ||
console.log(`Сервер запущен на http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// const fs = require('fs'); | ||
// | ||
// const path = require('path'); | ||
// | ||
// // Получаем полный путь к файлу library.json | ||
// const filePath = path.join(__dirname, 'library.json'); | ||
// | ||
// | ||
// // Чтение данных из JSON-файла | ||
// const rawData = fs.readFileSync(filePath, 'utf-8'); | ||
// const library = JSON.parse(rawData); | ||
// | ||
// // 1) Количество книг и список книг | ||
// function countAndListBooks() { | ||
// const count = library.length; | ||
// const bookList = library.map(book => book.title); | ||
// return [count, bookList]; | ||
// } | ||
// | ||
// | ||
// | ||
// module.exports = { | ||
// countAndListBooks, | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// const asyncHandler = require("express-async-handler"); | ||
// | ||
// // Обработчики написаны с использованием express-async-handler, что позволяет управлять асинхронными операциями | ||
// // в функциях-обработчиках без явного использования блоков try/catch или обработки ошибок с помощью catch(). | ||
// // Это упрощает обработку ошибок в асинхронных операциях. | ||
// | ||
// const { | ||
// countAndListAuthors, | ||
// getBooksByAuthor | ||
// } = require("./functions"); | ||
// const {getBooksByGenre} = require("./functions"); | ||
// | ||
// // отображает список всех авторов. | ||
// exports.author_list = asyncHandler(async (req, res, next) => { | ||
// const allAuthors = countAndListAuthors()[1] | ||
// res.render("author_list", { | ||
// title: "Список авторов", | ||
// author_list: allAuthors, | ||
// }); | ||
// }); | ||
// | ||
// exports.author_detail = asyncHandler(async (req, res, next) => { | ||
// const [author, allBooksByAuthor] = [ | ||
// getBooksByAuthor(req.params.id)[0], | ||
// getBooksByAuthor(req.params.id)[1], | ||
// ] | ||
// | ||
// if (author === null) { | ||
// const err = new Error("Author not found"); | ||
// err.status = 404; | ||
// return next(err); | ||
// } | ||
// | ||
// res.render("author_detail", { | ||
// title: "Список книг данного автора", | ||
// author: author, | ||
// author_books: allBooksByAuthor, | ||
// }); | ||
// }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const asyncHandler = require("express-async-handler"); | ||
const {importData} = require("../import"); | ||
|
||
|
||
// Обработчики написаны с использованием express-async-handler, что позволяет управлять асинхронными операциями | ||
// в функциях-обработчиках без явного использования блоков try/catch или обработки ошибок с помощью catch(). | ||
// Это упрощает обработку ошибок в асинхронных операциях. | ||
|
||
const { | ||
// countAndListGenres, | ||
// getBooksByGenre, | ||
} = require("./functions"); | ||
|
||
exports.index = asyncHandler(async (req, res) => { | ||
res.render('index'); | ||
}); | ||
|
||
exports.import = asyncHandler(async (req, res) => { | ||
await importData(); | ||
res.send('Данные успешно импортированы.'); | ||
}); | ||
|
||
exports.streets = asyncHandler(async (req, res) => { | ||
// Используем AQL-запрос для получения всех улиц | ||
const cursor = await db.query('FOR street IN streets RETURN street'); | ||
const streets = await cursor.all(); | ||
res.render('streets', { streets }); | ||
}); | ||
|
||
exports.houses = asyncHandler(async (req, res) => { | ||
const streetKey = req.params.key; | ||
const streetId = `streets/${streetKey}`; | ||
console.log(`Запрос на получение домов для streetId: ${streetId}`); | ||
|
||
const query = ` | ||
FOR house IN houses | ||
FILTER house._id IN ( | ||
FOR edge IN located_at | ||
FILTER edge._to == @streetId | ||
RETURN edge._from | ||
) | ||
RETURN house | ||
`; | ||
const bindVars = { streetId }; | ||
const cursor = await db.query(query, bindVars); | ||
const houses = await cursor.all(); | ||
console.log(`Найдено домов: ${houses.length}`); | ||
console.log('Дома:', houses); | ||
res.render('houses', { houses, streetKey }); | ||
}); | ||
|
||
// // Отображает страницу с подробной информацией о конкретном жанре на основе его идентификатора | ||
// exports.genre_detail = asyncHandler(async (req, res, next) => { | ||
// // Get details of genre and all associated books (in parallel) | ||
// const [genre, booksInGenre] = [ | ||
// getBooksByGenre(req.params.id)[0], | ||
// getBooksByGenre(req.params.id)[1], | ||
// ] | ||
// if (genre === null) { | ||
// // No results. | ||
// const err = new Error("Genre not found"); | ||
// err.status = 404; | ||
// return next(err); | ||
// } | ||
// | ||
// res.render("genre_detail", { | ||
// title: "Книги заданного жанра", | ||
// genre: genre, | ||
// genre_books: booksInGenre, | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
[ | ||
{ | ||
"_key": "avangardnaya_2a", | ||
"address": "ул. Авангардная, 2 Литер А", | ||
"year": 1961, | ||
"floors": 5, | ||
"apartments": 78, | ||
"condition": "Исправный", | ||
"management_company": "УК «Жилищник»", | ||
"series_type": "ЛГ-528" | ||
}, | ||
{ | ||
"_key": "avangardnaya_2k2a", | ||
"address": "ул. Авангардная, 2 корпус 2 Литер А", | ||
"year": 1993, | ||
"floors": 10, | ||
"apartments": 80, | ||
"condition": "Исправный", | ||
"management_company": "УК «Жилищник»", | ||
"series_type": "Индивидуальный" | ||
}, | ||
{ | ||
"_key": "avangardnaya_3a", | ||
"address": "ул. Авангардная, 3 Литер А", | ||
"year": 1969, | ||
"floors": 9, | ||
"apartments": 231, | ||
"condition": "Исправный", | ||
"management_company": "УК «Жилищник»", | ||
"series_type": "ЛГ-528" | ||
}, | ||
{ | ||
"_key": "aviakonstruktorov_1a", | ||
"address": "пр-кт Авиаконструкторов, 1 Литер А", | ||
"year": 1988, | ||
"floors": 16, | ||
"apartments": 463, | ||
"condition": "Исправный", | ||
"management_company": "УК «ЖКС №4 приморского района»", | ||
"series_type": "137" | ||
}, | ||
{ | ||
"_key": "aviakonstruktorov_2a", | ||
"address": "пр-кт Авиаконструкторов, 2 Литер А", | ||
"year": 2008, | ||
"floors": 25, | ||
"apartments": 493, | ||
"condition": "Исправный", | ||
"management_company": "ТСЖ «Авиатор-2»", | ||
"series_type": "Индивидуальный" | ||
}, | ||
{ | ||
"_key": "babushkina_7a", | ||
"address": "ул. Бабушкина, 7 Литер А", | ||
"year": 1959, | ||
"floors": 5, | ||
"apartments": 54, | ||
"condition": "Исправный", | ||
"management_company": "УК «ЖКС №2 невского района»", | ||
"series_type": "1-507" | ||
}, | ||
{ | ||
"_key": "babushkina_8a", | ||
"address": "ул. Бабушкина, 8 Литер А", | ||
"year": 1959, | ||
"floors": 5, | ||
"apartments": 38, | ||
"condition": "Исправный", | ||
"management_company": "УК «ЖКС №2 невского района»", | ||
"series_type": "Индивидуальный" | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ "_from": "houses/avangardnaya_2a", "_to": "streets/avangardnaya" }, | ||
{ "_from": "houses/avangardnaya_2k2a", "_to": "streets/avangardnaya" }, | ||
{ "_from": "houses/avangardnaya_3a", "_to": "streets/avangardnaya" }, | ||
{ "_from": "houses/aviakonstruktorov_1a", "_to": "streets/aviakonstruktorov" }, | ||
{ "_from": "houses/aviakonstruktorov_2a", "_to": "streets/aviakonstruktorov" }, | ||
{ "_from": "houses/babushkina_7a", "_to": "streets/babushkina" }, | ||
{ "_from": "houses/babushkina_8a", "_to": "streets/babushkina" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ "_key": "avangardnaya", "name": "Авангардная" }, | ||
{ "_key": "aviakonstruktorov", "name": "Авиаконструкторов проспект" }, | ||
{ "_key": "babushkina", "name": "Бабушкина" } | ||
] | ||
|
58 changes: 33 additions & 25 deletions
58
hello_world/docker-compose.yml → citywalls2/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
version: '3.8' | ||
|
||
services: | ||
arango: | ||
image: arangodb:latest | ||
environment: | ||
- ARANGO_ROOT_PASSWORD=password | ||
ports: | ||
- "8529:8529" | ||
volumes: | ||
- arango_data:/var/lib/arangodb3 | ||
|
||
nodeapp: | ||
build: . | ||
depends_on: | ||
- arango | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
- NODE_ENV=production | ||
volumes: | ||
- .:/usr/src/app | ||
|
||
volumes: | ||
arango_data: | ||
version: '3.8' | ||
|
||
services: | ||
arango: | ||
image: arangodb:latest | ||
environment: | ||
- ARANGO_ROOT_PASSWORD=password | ||
ports: | ||
- "8529:8529" | ||
volumes: | ||
- arango_data:/var/lib/arangodb3 | ||
command: ["arangod", "--server.endpoint", "tcp://0.0.0.0:8529"] | ||
|
||
nodeapp: | ||
build: . | ||
depends_on: | ||
- arango | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
- NODE_ENV=production | ||
- ARANGO_URL=http://arango:8529 | ||
- ARANGO_USER=root | ||
- ARANGO_PASSWORD=password | ||
- ARANGO_DB=city_data | ||
- PORT=3000 | ||
# Удаляем монтирование тома | ||
# volumes: | ||
# - .:/usr/src/app | ||
command: sh -c "npm run import && npm start" | ||
|
||
volumes: | ||
arango_data: |
Oops, something went wrong.