dist erase

This commit is contained in:
Primakov Alexandr Alexandrovich 2022-04-19 08:27:59 +03:00
parent 544046f43d
commit e4d170e545
14 changed files with 1 additions and 146 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules/
.env
dist/

1
dist/config.d.ts vendored
View File

@ -1 +0,0 @@
export {};

4
dist/config.js vendored
View File

@ -1,4 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dotenv_1 = require("dotenv");
(0, dotenv_1.config)();

1
dist/main.d.ts vendored
View File

@ -1 +0,0 @@
import './config';

19
dist/main.js vendored
View File

@ -1,19 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const cookie_session_1 = __importDefault(require("cookie-session"));
require("./config");
const error_handling_1 = require("./utils/error-handling");
const routes_1 = require("./routes");
const app = (0, express_1.default)();
const port = process.env.RED_CODER_BH_PORT;
app.use(express_1.default.json());
app.use((0, cookie_session_1.default)({ secret: process.env.COOKIE_SESSION }));
app.use(routes_1.router);
app.use(error_handling_1.errorHandle);
app.listen(port, () => {
console.log(`listen on http://localhost:${port}`);
});

View File

@ -1 +0,0 @@
export declare const authRouter: import("express-serve-static-core").Router;

68
dist/routes/auth.js vendored
View File

@ -1,68 +0,0 @@
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authRouter = void 0;
const express_1 = require("express");
const pbkdf2_password_1 = __importDefault(require("pbkdf2-password"));
const uuid_1 = require("uuid");
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const express_jwt_1 = __importDefault(require("express-jwt"));
const makeHash = (0, pbkdf2_password_1.default)();
exports.authRouter = (0, express_1.Router)();
const requiredFields = (fields) => (req, res, next) => {
for (const fieldName of fields) {
if (!req.body[fieldName]) {
throw new Error(`Field ${fieldName} does\'t set`);
}
}
next();
};
const users = [];
exports.authRouter.get('/users', (0, express_jwt_1.default)({ secret: process.env.JWT_SECRET_STRING, algorithms: ['HS256'] }), (req, res) => {
res.send(users);
});
exports.authRouter.post('/sign-in', requiredFields(['password', 'login']), (req, res) => {
const { password, login } = req.body;
const user = users.find(u => u.login === login);
if (!user) {
res.status(400).send({ error: 'Login or password does\'t match' });
return;
}
makeHash({ password, salt: user.salt }, (err, pass, salt, hash) => {
if (err)
throw err;
if (user.hash === hash) {
const { hash: _hash, salt: _salt } = user, cleanUser = __rest(user, ["hash", "salt"]);
req.session.user = cleanUser;
const token = jsonwebtoken_1.default.sign(cleanUser, process.env.JWT_SECRET_STRING, {});
return res.send({ token, user: cleanUser });
}
res.status(400).send({ error: 'Login or password does\'t match' });
});
});
exports.authRouter.post('/sign-up', requiredFields(['password', 'login', 'email']), (req, res, next) => {
const _a = req.body, { password, login } = _a, rest = __rest(_a, ["password", "login"]);
makeHash({ password }, function (err, pass, salt, hash) {
if (err)
throw err;
const newUser = Object.assign(Object.assign({ id: (0, uuid_1.v4)() }, rest), { login,
salt,
hash });
users.push(newUser);
const { hash: _hash, salt: _salt } = newUser, cleanUser = __rest(newUser, ["hash", "salt"]);
res.send(cleanUser);
});
});

View File

@ -1,19 +0,0 @@
{
"data": [
{
"title": "Подсказка на сегодня",
"body": "Подберите задачки под свой уровень сложности, решите её и наращивайте навык",
"icon": "allGood"
},
{
"title": "Подсказка на завтра",
"body": "Не забудь сутра выпить кофе",
"icon": "coding"
},
{
"title": "Подсказка на вчера",
"body": "Забыл сутра выпить кофе?",
"icon": "askingQuestion"
}
]
}

View File

@ -1 +0,0 @@
export declare const bannerRouter: import("express-serve-static-core").Router;

View File

@ -1,12 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bannerRouter = void 0;
const express_1 = require("express");
const data_json_1 = __importDefault(require("./data.json"));
exports.bannerRouter = (0, express_1.Router)();
exports.bannerRouter.get('/banner-data', (req, res) => {
res.send(data_json_1.default);
});

View File

@ -1 +0,0 @@
export declare const router: import("express-serve-static-core").Router;

View File

@ -1,9 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.router = void 0;
const express_1 = require("express");
const auth_1 = require("./auth");
const banner_1 = require("./banner");
exports.router = (0, express_1.Router)();
exports.router.use(banner_1.bannerRouter);
exports.router.use('/auth', auth_1.authRouter);

View File

@ -1 +0,0 @@
export declare const errorHandle: (error: any, req: any, res: any, next: any) => void;

View File

@ -1,9 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorHandle = void 0;
const errorHandle = (error, req, res, next) => {
res.status(500).send({
error: error.message || 'some error'
});
};
exports.errorHandle = errorHandle;