mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
feat: add sample multi-user support
feat: update README
This commit is contained in:
parent
41f351786f
commit
62d88380e0
19 changed files with 314 additions and 49 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const express = require('express');
|
||||
const session = require('express-session')
|
||||
const dbConnect = require('../models/dbConnect');
|
||||
const { migrateDb } = require('../models');
|
||||
const path = require('path');
|
||||
|
|
@ -7,6 +8,7 @@ const routes = require('./routes');
|
|||
const app = express();
|
||||
const port = process.env.PORT || 3080;
|
||||
const host = process.env.HOST || 'localhost'
|
||||
const userSystemEnabled = process.env.ENABLE_USER_SYSTEM || false
|
||||
const projectPath = path.join(__dirname, '..', '..', 'client');
|
||||
dbConnect().then(() => {
|
||||
console.log('Connected to MongoDB');
|
||||
|
|
@ -16,17 +18,38 @@ dbConnect().then(() => {
|
|||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.static(path.join(projectPath, 'public')));
|
||||
app.set('trust proxy', 1) // trust first proxy
|
||||
app.use(session({
|
||||
secret: 'chatgpt-clone-random-secrect',
|
||||
resave: false,
|
||||
saveUninitialized: true,
|
||||
}))
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
app.get('/', routes.authenticatedOrRedirect, function (req, res) {
|
||||
console.log(path.join(projectPath, 'public', 'index.html'));
|
||||
res.sendFile(path.join(projectPath, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
app.use('/api/ask', routes.ask);
|
||||
app.use('/api/messages', routes.messages);
|
||||
app.use('/api/convos', routes.convos);
|
||||
app.use('/api/customGpts', routes.customGpts);
|
||||
app.use('/api/prompts', routes.prompts);
|
||||
app.get('/api/me', function (req, res) {
|
||||
if (userSystemEnabled) {
|
||||
const user = req?.session?.user
|
||||
|
||||
if (user)
|
||||
res.send(JSON.stringify({username: user?.username, display: user?.display}));
|
||||
else
|
||||
res.send(JSON.stringify(null));
|
||||
} else {
|
||||
res.send(JSON.stringify({username: 'anonymous_user', display: 'Anonymous User'}));
|
||||
}
|
||||
});
|
||||
|
||||
app.use('/api/ask', routes.authenticatedOr401, routes.ask);
|
||||
app.use('/api/messages', routes.authenticatedOr401, routes.messages);
|
||||
app.use('/api/convos', routes.authenticatedOr401, routes.convos);
|
||||
app.use('/api/customGpts', routes.authenticatedOr401, routes.customGpts);
|
||||
app.use('/api/prompts', routes.authenticatedOr401, routes.prompts);
|
||||
app.use('/auth', routes.auth);
|
||||
|
||||
|
||||
app.listen(port, host, () => {
|
||||
if (host=='0.0.0.0')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue