mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* chore: fix `endpoint` typescript issues and typo in console info message * feat(api): files GET endpoint and save only file_id references to messages * refactor(client): `useGetFiles` query hook, update file types, optimistic update of filesQuery on file upload * refactor(buildTree): update to use params object and accept fileMap * feat: map files to messages; refactor(ChatView): messages only available after files are fetched * fix: fetch files only when authenticated * feat(api): AppService - rename app.locals.configs to app.locals.paths - load custom config use fileStrategy from yaml config in app.locals * refactor: separate Firebase and Local strategies, call based on config * refactor: modularize file strategies and employ with use of DALL-E * refactor(librechat.yaml): add fileStrategy field * feat: add source to MongoFile schema, as well as BatchFile, and ExtendedFile types * feat: employ file strategies for upload/delete files * refactor(deleteFirebaseFile): add user id validation for firebase file deletion * chore(deleteFirebaseFile): update jsdocs * feat: employ strategies for vision requests * fix(client): handle messages with deleted files * fix(client): ensure `filesToDelete` always saves/sends `file.source` * feat(openAI): configurable `resendImages` and `imageDetail` * refactor(getTokenCountForMessage): recursive process only when array of Objects and only their values (not keys) aside from `image_url` types * feat(OpenAIClient): calculateImageTokenCost * chore: remove comment * refactor(uploadAvatar): employ fileStrategy for avatars, from social logins or user upload * docs: update docs on how to configure fileStrategy * fix(ci): mock winston and winston related modules, update DALLE3.spec.js with changes made * refactor(redis): change terminal message to reflect current development state * fix(DALL-E-2): pass fileStrategy to dall-e
118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
require('dotenv').config();
|
|
const path = require('path');
|
|
require('module-alias')({ base: path.resolve(__dirname, '..') });
|
|
const cors = require('cors');
|
|
const express = require('express');
|
|
const passport = require('passport');
|
|
const mongoSanitize = require('express-mongo-sanitize');
|
|
const errorController = require('./controllers/ErrorController');
|
|
const { jwtLogin, passportLogin } = require('~/strategies');
|
|
const configureSocialLogins = require('./socialLogins');
|
|
const { connectDb, indexSync } = require('~/lib/db');
|
|
const AppService = require('./services/AppService');
|
|
const noIndex = require('./middleware/noIndex');
|
|
const { logger } = require('~/config');
|
|
|
|
const routes = require('./routes');
|
|
|
|
const { PORT, HOST, ALLOW_SOCIAL_LOGIN } = process.env ?? {};
|
|
|
|
const port = Number(PORT) || 3080;
|
|
const host = HOST || 'localhost';
|
|
|
|
const startServer = async () => {
|
|
await connectDb();
|
|
logger.info('Connected to MongoDB');
|
|
await indexSync();
|
|
|
|
const app = express();
|
|
await AppService(app);
|
|
|
|
// Middleware
|
|
app.use(noIndex);
|
|
app.use(errorController);
|
|
app.use(express.json({ limit: '3mb' }));
|
|
app.use(mongoSanitize());
|
|
app.use(express.urlencoded({ extended: true, limit: '3mb' }));
|
|
app.use(express.static(app.locals.paths.dist));
|
|
app.use(express.static(app.locals.paths.publicPath));
|
|
app.set('trust proxy', 1); // trust first proxy
|
|
app.use(cors());
|
|
|
|
if (!ALLOW_SOCIAL_LOGIN) {
|
|
console.warn(
|
|
'Social logins are disabled. Set Environment Variable "ALLOW_SOCIAL_LOGIN" to true to enable them.',
|
|
);
|
|
}
|
|
|
|
// OAUTH
|
|
app.use(passport.initialize());
|
|
passport.use(await jwtLogin());
|
|
passport.use(passportLogin());
|
|
|
|
if (ALLOW_SOCIAL_LOGIN?.toLowerCase() === 'true') {
|
|
configureSocialLogins(app);
|
|
}
|
|
|
|
app.use('/oauth', routes.oauth);
|
|
// API Endpoints
|
|
app.use('/api/auth', routes.auth);
|
|
app.use('/api/keys', routes.keys);
|
|
app.use('/api/user', routes.user);
|
|
app.use('/api/search', routes.search);
|
|
app.use('/api/ask', routes.ask);
|
|
app.use('/api/edit', routes.edit);
|
|
app.use('/api/messages', routes.messages);
|
|
app.use('/api/convos', routes.convos);
|
|
app.use('/api/presets', routes.presets);
|
|
app.use('/api/prompts', routes.prompts);
|
|
app.use('/api/tokenizer', routes.tokenizer);
|
|
app.use('/api/endpoints', routes.endpoints);
|
|
app.use('/api/balance', routes.balance);
|
|
app.use('/api/models', routes.models);
|
|
app.use('/api/plugins', routes.plugins);
|
|
app.use('/api/config', routes.config);
|
|
app.use('/api/assistants', routes.assistants);
|
|
app.use('/api/files', routes.files);
|
|
|
|
app.use((req, res) => {
|
|
res.status(404).sendFile(path.join(app.locals.paths.dist, 'index.html'));
|
|
});
|
|
|
|
app.listen(port, host, () => {
|
|
if (host == '0.0.0.0') {
|
|
logger.info(
|
|
`Server listening on all interfaces at port ${port}. Use http://localhost:${port} to access it`,
|
|
);
|
|
} else {
|
|
logger.info(`Server listening at http://${host == '0.0.0.0' ? 'localhost' : host}:${port}`);
|
|
}
|
|
});
|
|
};
|
|
|
|
startServer();
|
|
|
|
let messageCount = 0;
|
|
process.on('uncaughtException', (err) => {
|
|
if (!err.message.includes('fetch failed')) {
|
|
logger.error('There was an uncaught error:', err);
|
|
}
|
|
|
|
if (err.message.includes('fetch failed')) {
|
|
if (messageCount === 0) {
|
|
logger.warn('Meilisearch error, search will be disabled');
|
|
messageCount++;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (err.message.includes('OpenAIError') || err.message.includes('ChatCompletionMessage')) {
|
|
logger.error(
|
|
'\n\nAn Uncaught `OpenAIError` error may be due to your reverse-proxy setup or stream configuration, or a bug in the `openai` node package.',
|
|
);
|
|
return;
|
|
}
|
|
|
|
process.exit(1);
|
|
});
|