Compare commits
5 Commits
caramel
...
32a29160cb
| Author | SHA1 | Date | |
|---|---|---|---|
| 32a29160cb | |||
| 8f2d7c19ac | |||
| 289efcff07 | |||
| 2124fb0bd5 | |||
| fa10a84380 |
@@ -1 +1,7 @@
|
|||||||
PORT=5000
|
PORT=5000
|
||||||
|
|
||||||
|
DB_NAME=unreal_amogus
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWD=amogus_life_420
|
||||||
|
DB_HOST=192.168.192.150
|
||||||
|
DB_PORT=5432
|
||||||
23
server/db.js
23
server/db.js
@@ -1,4 +1,7 @@
|
|||||||
const {Sequelize} = require('sequelize')
|
const { Sequelize } = require('sequelize')
|
||||||
|
/* const dotenv = require('dotenv'); */
|
||||||
|
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
module.exports = new Sequelize(
|
module.exports = new Sequelize(
|
||||||
process.env.DB_NAME, // Название БД
|
process.env.DB_NAME, // Название БД
|
||||||
@@ -6,7 +9,19 @@ module.exports = new Sequelize(
|
|||||||
process.env.DB_PASSWORD, // ПАРОЛЬ
|
process.env.DB_PASSWORD, // ПАРОЛЬ
|
||||||
{
|
{
|
||||||
dialect: 'postgres',
|
dialect: 'postgres',
|
||||||
host: '192.168.192.150',
|
host: process.env.DB_HOST,
|
||||||
port: '5432'
|
port: process.env.DB_PORT
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
const connectDb = async () => {
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
console.log('Подключение к PostgreSQL успешно');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка подключения:', error.stack);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { Sequelize, connectDb };
|
||||||
@@ -1,8 +1,45 @@
|
|||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
const sequelize = require('./db')
|
||||||
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 5000
|
const PORT = process.env.PORT || 5000
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
|
|
||||||
|
|
||||||
|
process.on('uncaughtException', function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/* const nachalo = async () => {
|
||||||
|
try {
|
||||||
|
await sequelize.authenticate()
|
||||||
|
await sequelize.sync()
|
||||||
|
|
||||||
|
|
||||||
|
app.listen(PORT, () => console.log(`Server started on port http://localhost:${PORT}`))
|
||||||
|
} catch(errors) {
|
||||||
|
console.log(errors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nachalo() */
|
||||||
|
|
||||||
|
app.get('/api/data', (req, res) => {
|
||||||
|
db.query('SELECT * FROM your_table', (error, results) => {
|
||||||
|
if (error) throw error;
|
||||||
|
res.json(results);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Сервер запущен на порту http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.send('Welcome to the homepage!');
|
||||||
|
});
|
||||||
56
server/models/models.js
Normal file
56
server/models/models.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
const sequelize = require('sequelize')
|
||||||
|
const DataTypes = require('../db')
|
||||||
|
|
||||||
|
const User = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const Cart = sequelize.define('cart', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
userId: { type: DataTypes.INTEGER, unique: true }
|
||||||
|
})
|
||||||
|
|
||||||
|
const CartDevice = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const device = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const deviceInfo = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const rating = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const Type = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
|
|
||||||
|
const Brand = sequelize.define('user', {
|
||||||
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
email: { type: DataTypes.STRING, unique: true },
|
||||||
|
password: { type: DataTypes.STRING },
|
||||||
|
role: { type: DataTypes.STRING, defaultValue: "USER" }
|
||||||
|
})
|
||||||
3131
server/node_modules/.package-lock.json
generated
vendored
3131
server/node_modules/.package-lock.json
generated
vendored
File diff suppressed because it is too large
Load Diff
3143
server/package-lock.json
generated
3143
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -15,9 +15,12 @@
|
|||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-fileupload": "^1.2.1",
|
"express-fileupload": "^1.2.1",
|
||||||
|
"install": "^0.13.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
"npm": "^11.1.0",
|
||||||
"pg": "^8.13.1",
|
"pg": "^8.13.1",
|
||||||
"pg-hstore": "^2.3.4",
|
"pg-hstore": "^2.3.4",
|
||||||
|
"postgresql": "^0.0.1",
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user