первый коммит, надеюсь последний.
Сделанно: 1. минимально рабочий бэк 2. 2 модели 3. 1 миграция
This commit is contained in:
+133
@@ -0,0 +1,133 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# мои папки которые надо бы разкоментить
|
||||||
|
#app/config/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
secret: "secret-key"
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
HOST: "localhost",
|
||||||
|
USER: "postgres",
|
||||||
|
PASSWORD: "test",
|
||||||
|
DB: "sicrets_db",
|
||||||
|
dialect: "postgres",
|
||||||
|
pool: {
|
||||||
|
max: 5,
|
||||||
|
min: 0,
|
||||||
|
acquire: 30000,
|
||||||
|
idle: 10000
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
const db = require("../models");
|
||||||
|
const config = require("../config/auth.config");
|
||||||
|
const User = db.user;
|
||||||
|
const Role = db.role;
|
||||||
|
const Op = db.Sequelize.Op;
|
||||||
|
const jwt = require("jsonwebtoken");
|
||||||
|
const bcrypt = require("bcryptjs");
|
||||||
|
|
||||||
|
exports.sign_up = (req, res) => {
|
||||||
|
User.create({
|
||||||
|
username: req.body.username,
|
||||||
|
email: req.body.email,
|
||||||
|
password: bcrypt.hashSync(req.body.password, 8)
|
||||||
|
})
|
||||||
|
.then(user => {
|
||||||
|
if (req.body.roles) {
|
||||||
|
Role.findAll({
|
||||||
|
where: {
|
||||||
|
name: {
|
||||||
|
[Op.or]: req.body.roles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(roles => {
|
||||||
|
user.setRoles(roles).then(() => {
|
||||||
|
res.send({ message: "Регистрация пользователя прошла успешно" });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
user.setRoles([1]).then(() => {
|
||||||
|
res.send({ message: "Регистрация пользователя прошла успешно" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.status(500).send({ message: err.message });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.sign_in = (req, res) => {
|
||||||
|
User.findOne({
|
||||||
|
where: {
|
||||||
|
username: req.body.username
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(user => {
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).send({ message: "Пользователь не найден" });
|
||||||
|
}
|
||||||
|
const passwordIsValid = bcrypt.compareSync(
|
||||||
|
req.body.password,
|
||||||
|
user.password
|
||||||
|
);
|
||||||
|
if (!passwordIsValid) {
|
||||||
|
return res.status(401).send({
|
||||||
|
accessToken: null,
|
||||||
|
message: "Неправельный пароль"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const token = jwt.sign({ id: user.id },
|
||||||
|
config.secret,
|
||||||
|
{
|
||||||
|
algorithm: 'HS256',
|
||||||
|
allowInsecureKeySizes: true,
|
||||||
|
expiresIn: 86400,
|
||||||
|
});
|
||||||
|
let authorities = [];
|
||||||
|
user.getRoles().then(roles => {
|
||||||
|
for (let i = 0; i < roles.length; i++) {
|
||||||
|
authorities.push("ROLE_" + roles[i].name.toUpperCase());
|
||||||
|
}
|
||||||
|
res.status(200).send({
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
roles: authorities,
|
||||||
|
accessToken: token
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.status(500).send({ message: err.message });
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
exports.allAccess = (req, res) => {
|
||||||
|
res.status(200).send("Это контент для всех");
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.userBoard = (req, res) => {
|
||||||
|
res.status(200).send("Тут авторизоваться надо бы");
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.adminBoard = (req, res) => {
|
||||||
|
res.status(200).send("Тут нужно быть аж админом");
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.moderatorBoard = (req, res) => {
|
||||||
|
res.status(200).send("Ну а тут модером");
|
||||||
|
};
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
const jwt = require("jsonwebtoken");
|
||||||
|
const config = require("../config/auth.config.js");
|
||||||
|
const db = require("../models");
|
||||||
|
const User = db.user;
|
||||||
|
|
||||||
|
verifyToken = (req, res, next) => {
|
||||||
|
let token = req.headers["x-access-token"];
|
||||||
|
if (!token) {
|
||||||
|
return res.status(403).send({
|
||||||
|
message: "Токена нету у вас"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
jwt.verify(token,
|
||||||
|
config.secret,
|
||||||
|
(err, decoded) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(401).send({
|
||||||
|
message: "Вы не авторизованны",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
req.userId = decoded.id;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
isAdmin = (req, res, next) => {
|
||||||
|
User.findByPk(req.userId).then(user => {
|
||||||
|
user.getRoles().then(roles => {
|
||||||
|
for (let i = 0; i < roles.length; i++) {
|
||||||
|
if (roles[i].name === "admin") {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.status(403).send({
|
||||||
|
message: "Вам нужна роль админ"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
isModerator = (req, res, next) => {
|
||||||
|
User.findByPk(req.userId).then(user => {
|
||||||
|
user.getRoles().then(roles => {
|
||||||
|
for (let i = 0; i < roles.length; i++) {
|
||||||
|
if (roles[i].name === "moderator") {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.status(403).send({
|
||||||
|
message: "Вам нужна роль модератор"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
isModeratorOrAdmin = (req, res, next) => {
|
||||||
|
User.findByPk(req.userId).then(user => {
|
||||||
|
user.getRoles().then(roles => {
|
||||||
|
for (let i = 0; i < roles.length; i++) {
|
||||||
|
if (roles[i].name === "moderator") {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (roles[i].name === "admin") {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.status(403).send({
|
||||||
|
message: "Нужна роль либо модератор, любо админ"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const authJwt = {
|
||||||
|
verifyToken: verifyToken,
|
||||||
|
isAdmin: isAdmin,
|
||||||
|
isModerator: isModerator,
|
||||||
|
isModeratorOrAdmin: isModeratorOrAdmin
|
||||||
|
};
|
||||||
|
module.exports = authJwt;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const authJwt = require("./authJwt");
|
||||||
|
const verifySignUp = require("./verifySignUp");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
authJwt,
|
||||||
|
verifySignUp
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
const db = require("../models");
|
||||||
|
const ROLES = db.ROLES;
|
||||||
|
const User = db.user;
|
||||||
|
|
||||||
|
checkDuplicateUsernameOrEmail = (req, res, next) => {
|
||||||
|
User.findOne({
|
||||||
|
where: {
|
||||||
|
username: req.body.username
|
||||||
|
}
|
||||||
|
}).then(user => {
|
||||||
|
if (user) {
|
||||||
|
res.status(400).send({
|
||||||
|
message: "Ошибка. Такой ник уже есть."
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
User.findOne({
|
||||||
|
where: {
|
||||||
|
email: req.body.email
|
||||||
|
}
|
||||||
|
}).then(user => {
|
||||||
|
if (user) {
|
||||||
|
res.status(400).send({
|
||||||
|
message: "Ошибка. Такая почта уже есть."
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
checkRolesExisted = (req, res, next) => {
|
||||||
|
if (req.body.roles) {
|
||||||
|
for (let i = 0; i < req.body.roles.length; i++) {
|
||||||
|
if (!ROLES.includes(req.body.roles[i])) {
|
||||||
|
res.status(400).send({
|
||||||
|
message: "Ошибка. Нет такой роли = " + req.body.roles[i]
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
const verifySignUp = {
|
||||||
|
checkDuplicateUsernameOrEmail: checkDuplicateUsernameOrEmail,
|
||||||
|
checkRolesExisted: checkRolesExisted
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = verifySignUp;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
const config = require("../config/db.config.js");
|
||||||
|
|
||||||
|
const Sequelize = require("sequelize");
|
||||||
|
const sequelize = new Sequelize(
|
||||||
|
config.DB,
|
||||||
|
config.USER,
|
||||||
|
config.PASSWORD,
|
||||||
|
{
|
||||||
|
host: config.HOST,
|
||||||
|
dialect: config.dialect,
|
||||||
|
pool: {
|
||||||
|
max: config.pool.max,
|
||||||
|
min: config.pool.min,
|
||||||
|
acquire: config.pool.acquire,
|
||||||
|
idle: config.pool.idle
|
||||||
|
},
|
||||||
|
logging: false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const db = {};
|
||||||
|
|
||||||
|
db.Sequelize = Sequelize;
|
||||||
|
db.sequelize = sequelize;
|
||||||
|
|
||||||
|
db.user = require("../models/user.model.js")(sequelize, Sequelize);
|
||||||
|
db.role = require("../models/role.model.js")(sequelize, Sequelize);
|
||||||
|
|
||||||
|
db.role.belongsToMany(db.user, {
|
||||||
|
through: "user_roles"
|
||||||
|
});
|
||||||
|
db.user.belongsToMany(db.role, {
|
||||||
|
through: "user_roles"
|
||||||
|
});
|
||||||
|
|
||||||
|
db.ROLES = ["user", "admin", "moderator"];
|
||||||
|
|
||||||
|
module.exports = db;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
return sequelize.define("roles", {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
return sequelize.define("users", {
|
||||||
|
username: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
const { verifySignUp } = require("../middleware");
|
||||||
|
const controller = require("../controllers/auth.controller");
|
||||||
|
|
||||||
|
module.exports = function(app) {
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
res.header(
|
||||||
|
"Access-Control-Allow-Headers",
|
||||||
|
"x-access-token, Origin, Content-Type, Accept"
|
||||||
|
);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
app.post(
|
||||||
|
"/api/auth/sign_up",
|
||||||
|
[
|
||||||
|
verifySignUp.checkDuplicateUsernameOrEmail,
|
||||||
|
verifySignUp.checkRolesExisted
|
||||||
|
],
|
||||||
|
controller.sign_up
|
||||||
|
);
|
||||||
|
app.post("/api/auth/sign_in", controller.sign_in);
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
const { authJwt } = require("../middleware");
|
||||||
|
const controller = require("../controllers/user.controller");
|
||||||
|
|
||||||
|
module.exports = function(app) {
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
res.header(
|
||||||
|
"Access-Control-Allow-Headers",
|
||||||
|
"x-access-token, Origin, Content-Type, Accept"
|
||||||
|
);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
app.get("/api/get/all", controller.allAccess);
|
||||||
|
app.get(
|
||||||
|
"/api/get/user",
|
||||||
|
[authJwt.verifyToken],
|
||||||
|
controller.userBoard
|
||||||
|
);
|
||||||
|
app.get(
|
||||||
|
"/api/get/mod",
|
||||||
|
[authJwt.verifyToken, authJwt.isModerator],
|
||||||
|
controller.moderatorBoard
|
||||||
|
);
|
||||||
|
app.get(
|
||||||
|
"/api/get/admin",
|
||||||
|
[authJwt.verifyToken, authJwt.isAdmin],
|
||||||
|
controller.adminBoard
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"development": {
|
||||||
|
"username": "postgres",
|
||||||
|
"password": "test",
|
||||||
|
"database": "sicrets_db",
|
||||||
|
"host": "localhost",
|
||||||
|
"dialect": "postgres"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"username": "root",
|
||||||
|
"password": null,
|
||||||
|
"database": "database_test",
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"dialect": "mysql"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"username": "root",
|
||||||
|
"password": null,
|
||||||
|
"database": "database_production",
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"dialect": "mysql"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
/** @type {import('sequelize-cli').Migration} */
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.createTable('users', {
|
||||||
|
id: {
|
||||||
|
allowNull: false,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
type: Sequelize.INTEGER
|
||||||
|
},
|
||||||
|
username: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.dropTable('users');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
const {
|
||||||
|
Model
|
||||||
|
} = require('sequelize');
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class user extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* The `models/index` file will call this method automatically.
|
||||||
|
*/
|
||||||
|
static associate(models) {
|
||||||
|
// define association here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user.init({
|
||||||
|
username: DataTypes.STRING,
|
||||||
|
email: DataTypes.STRING,
|
||||||
|
password: DataTypes.STRING
|
||||||
|
}, {
|
||||||
|
sequelize,
|
||||||
|
modelName: 'user',
|
||||||
|
});
|
||||||
|
return user;
|
||||||
|
};
|
||||||
Generated
+1663
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "demo",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
|
"author": "Dmitrium12",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"bcryptjs": "^2.4.3",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"jsonwebtoken": "^9.0.1",
|
||||||
|
"pg": "^8.11.1",
|
||||||
|
"pg-hstore": "^2.3.4",
|
||||||
|
"sequelize": "^6.32.1",
|
||||||
|
"sequelize-cli": "^6.6.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const cors = require("cors");
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const corsOptions = {
|
||||||
|
origin: "http://localhost:3000"
|
||||||
|
};
|
||||||
|
|
||||||
|
app.use(cors(corsOptions));
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(express.urlencoded({extended: true}));
|
||||||
|
|
||||||
|
const db = require("./app/models");
|
||||||
|
db.sequelize.sync();
|
||||||
|
|
||||||
|
require('./app/routers/auth.routes')(app);
|
||||||
|
require('./app/routers/user.routes')(app);
|
||||||
|
|
||||||
|
const PORT = 8080;
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Сервер значится запустился на порту ${PORT}. Ну это значит, что это вроде работает.`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user