Commit 6bb78ce1 authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

Major advances for the TP13

parent e5070609
var session = require('express-session')
let RedisStore = require("connect-redis")(session)
const { createClient } = require("redis")
module.exports = async (app) => {
let redisClient = createClient({url: 'redis://localhost:6379', legacyMode: true})
redisClient.connect().then(()=>{
console.log("Redis connected~");
}).catch(console.error)
app.use(session({
store: new RedisStore({ client: redisClient }),
secret: 'my-secret',
resave: true,
rolling: true,
saveUninitialized: true,
name: 'access_token',
cookie: {
maxAge: 1000 * 60 * 60 * 2, // 2 hours
secure: false,
}
})
)
}
const express = require('express');
const cors = require('cors')
const bodyParser = require("body-parser");
var session = require('express-session');
const app = express();
app.use(cors({
origin: "http://localhost:3000"
origin: "http://localhost:3000",
credentials: true
}))
app.set('trust proxy', 1) //trust first proxy
app.use(session({
secret: 'my-secret',
resave: true,
rolling: true,
saveUninitialized: true,
name: 'accesstoken',
cookie: {
maxeAge: 1000 * 60 * 60 * 2,
sameSite: true,
secure: false}
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Connect session
require('./configs/session')(app);
// Connect the mongoDB here
require('./configs/db')();
app.use(require('./routes'));
app.listen(3001, () => console.log('App available on http://localhost/3001'));
app.use((err, req, res, next) => {
return res.json({
success: false,
code: 0,
error: err
})
})
app.listen(process.env.PORT || 3001, () => console.log('App available on http://localhost/3001'));
......@@ -4,7 +4,7 @@ const config = process.env;
const currentUser = (req, res, next) => {
if (!req.session.jwt) {
return res.send("You must log in");
return res.send({success: false, error: "You must log in"});
}
const user = jwt.verify(req.session.jwt, 'jwt-secret');
......@@ -14,14 +14,14 @@ const currentUser = (req, res, next) => {
const ensureSignedOut = (req, res, next) => {
if (req.session.jwt) {
return res.send("You are already logged in");
return res.send({success: false, error: "You are already logged in"});
}
next();
};
const ensureSignedIn = (req, res, next) => {
if (!req.session.jwt) {
return res.send("You must log in");
return res.send({success: false, error: "You must log in"});
}
next();
};
......
......@@ -7,7 +7,8 @@ var itemSchema = new mongoose.Schema({
},
category: {
type: mongoose.Schema.Types.ObjectId,
ref: "Categories"
ref: "Categories",
required: true
},
desc: String
}, {
......
File mode changed from 100644 to 100755
......@@ -28,6 +28,59 @@
"@hapi/hoek": "^9.0.0"
}
},
"node_modules/@redis/bloom": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.0.2.tgz",
"integrity": "sha512-EBw7Ag1hPgFzdznK2PBblc1kdlj5B5Cw3XwI9/oG7tSn85/HKy3X9xHy/8tm/eNXJYHLXHJL/pkwBpFMVVefkw==",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/client": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.1.0.tgz",
"integrity": "sha512-xO9JDIgzsZYDl3EvFhl6LC52DP3q3GCMUer8zHgKV6qSYsq1zB+pZs9+T80VgcRogrlRYhi4ZlfX6A+bHiBAgA==",
"dependencies": {
"cluster-key-slot": "1.1.0",
"generic-pool": "3.8.2",
"yallist": "4.0.0"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@redis/graph": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.0.1.tgz",
"integrity": "sha512-oDE4myMCJOCVKYMygEMWuriBgqlS5FqdWerikMoJxzmmTUErnTRRgmIDa2VcgytACZMFqpAOWDzops4DOlnkfQ==",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/json": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.3.tgz",
"integrity": "sha512-4X0Qv0BzD9Zlb0edkUoau5c1bInWSICqXAGrpwEltkncUwcxJIGEcVryZhLgb0p/3PkKaLIWkjhHRtLe9yiA7Q==",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/search": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@redis/search/-/search-1.0.6.tgz",
"integrity": "sha512-pP+ZQRis5P21SD6fjyCeLcQdps+LuTzp2wdUbzxEmNhleighDDTD5ck8+cYof+WLec4csZX7ks+BuoMw0RaZrA==",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/time-series": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.3.tgz",
"integrity": "sha512-OFp0q4SGrTH0Mruf6oFsHGea58u8vS/iI5+NpYdicaM+7BgqBZH8FFvNZ8rYYLrUO/QRqMq72NpXmxLVNcdmjA==",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@sideway/address": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.3.tgz",
......@@ -280,6 +333,22 @@
"node": ">= 0.8"
}
},
"node_modules/cluster-key-slot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/connect-redis": {
"version": "6.1.3",
"resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-6.1.3.tgz",
"integrity": "sha512-aaNluLlAn/3JPxRwdzw7lhvEoU6Enb+d83xnokUNhC9dktqBoawKWL+WuxinxvBLTz6q9vReTnUDnUslaz74aw==",
"engines": {
"node": ">=12"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
......@@ -504,6 +573,14 @@
"node": ">= 0.6"
}
},
"node_modules/generic-pool": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg==",
"engines": {
"node": ">= 4"
}
},
"node_modules/http-errors": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz",
......@@ -968,6 +1045,19 @@
"node": ">= 0.8"
}
},
"node_modules/redis": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.1.0.tgz",
"integrity": "sha512-5hvJ8wbzpCCiuN1ges6tx2SAh2XXCY0ayresBmu40/SGusWHFW86TAlIPpbimMX2DFHOX7RN34G2XlPA1Z43zg==",
"dependencies": {
"@redis/bloom": "1.0.2",
"@redis/client": "1.1.0",
"@redis/graph": "1.0.1",
"@redis/json": "1.0.3",
"@redis/search": "1.0.6",
"@redis/time-series": "1.0.3"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
......@@ -1235,6 +1325,11 @@
"engines": {
"node": ">=12"
}
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
}
}
# @redis/bloom
This package provides support for the [RedisBloom](https://redisbloom.io) module, which adds additional probabilistic data structures to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the RediBloom commands.
To use these extra commands, your Redis server must have the RedisBloom module installed.
RedisBloom provides the following probabilistic data structures:
* Bloom Filter: for checking set membership with a high degree of certainty.
* Cuckoo Filter: for checking set membership with a high degree of certainty.
* Count-Min Sketch: Determine the frequency of events in a stream.
* Top-K: Maintain a list of k most frequently seen items.
For complete examples, see `bloom-filter.js`, `cuckoo-filter.js`, `count-min-sketch.js` and `topk.js` in the Node Redis examples folder.
export declare const FIRST_KEY_INDEX = 1;
export declare function transformArguments(key: string, item: string): Array<string>;
export { transformBooleanReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
function transformArguments(key, item) {
return ['BF.ADD', key, item];
}
exports.transformArguments = transformArguments;
var generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return generic_transformers_1.transformBooleanReply; } });
export declare const FIRST_KEY_INDEX = 1;
export declare const IS_READ_ONLY = true;
export declare function transformArguments(key: string, item: string): Array<string>;
export { transformBooleanReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
exports.IS_READ_ONLY = true;
function transformArguments(key, item) {
return ['BF.EXISTS', key, item];
}
exports.transformArguments = transformArguments;
var generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return generic_transformers_1.transformBooleanReply; } });
export declare const FIRST_KEY_INDEX = 1;
export declare const IS_READ_ONLY = true;
export declare function transformArguments(key: string): Array<string>;
export declare type InfoRawReply = [
_: string,
capacity: number,
_: string,
size: number,
_: string,
numberOfFilters: number,
_: string,
numberOfInsertedItems: number,
_: string,
expansionRate: number
];
export interface InfoReply {
capacity: number;
size: number;
numberOfFilters: number;
numberOfInsertedItems: number;
expansionRate: number;
}
export declare function transformReply(reply: InfoRawReply): InfoReply;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
exports.IS_READ_ONLY = true;
function transformArguments(key) {
return ['BF.INFO', key];
}
exports.transformArguments = transformArguments;
function transformReply(reply) {
return {
capacity: reply[1],
size: reply[3],
numberOfFilters: reply[5],
numberOfInsertedItems: reply[7],
expansionRate: reply[9]
};
}
exports.transformReply = transformReply;
export declare const FIRST_KEY_INDEX = 1;
interface InsertOptions {
CAPACITY?: number;
ERROR?: number;
EXPANSION?: number;
NOCREATE?: true;
NONSCALING?: true;
}
export declare function transformArguments(key: string, items: string | Array<string>, options?: InsertOptions): Array<string>;
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
const generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
exports.FIRST_KEY_INDEX = 1;
function transformArguments(key, items, options) {
const args = ['BF.INSERT', key];
if (options?.CAPACITY) {
args.push('CAPACITY', options.CAPACITY.toString());
}
if (options?.ERROR) {
args.push('ERROR', options.ERROR.toString());
}
if (options?.EXPANSION) {
args.push('EXPANSION', options.EXPANSION.toString());
}
if (options?.NOCREATE) {
args.push('NOCREATE');
}
if (options?.NONSCALING) {
args.push('NONSCALING');
}
args.push('ITEMS');
(0, generic_transformers_1.pushVerdictArguments)(args, items);
return args;
}
exports.transformArguments = transformArguments;
var generic_transformers_2 = require("@redis/client/dist/lib/commands/generic-transformers");
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return generic_transformers_2.transformBooleanArrayReply; } });
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
export declare const FIRST_KEY_INDEX = 1;
export declare function transformArguments(key: string, iteretor: number, chunk: RedisCommandArgument): RedisCommandArguments;
export declare function transformReply(): 'OK';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
function transformArguments(key, iteretor, chunk) {
return ['BF.LOADCHUNK', key, iteretor.toString(), chunk];
}
exports.transformArguments = transformArguments;
export declare const FIRST_KEY_INDEX = 1;
export declare function transformArguments(key: string, items: Array<string>): Array<string>;
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
exports.FIRST_KEY_INDEX = 1;
function transformArguments(key, items) {
return ['BF.MADD', key, ...items];
}
exports.transformArguments = transformArguments;
var generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return generic_transformers_1.transformBooleanArrayReply; } });
export declare const FIRST_KEY_INDEX = 1;
export declare const IS_READ_ONLY = true;
export declare function transformArguments(key: string, items: Array<string>): Array<string>;
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment