mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
* Add files via upload * Create linode-setup.md * Create cloudflare-setup.md * Update cloudflare-setup.md * Delete 4-linode.png * Delete 3-linode.png * Add files via upload * Add files via upload * Update cloudflare-setup.md * Update linode-setup.md * Rename cloudflare-setup.md to cloudflare.md * Rename linode-setup.md to linode.md * Update mkdocs.yml * Update cloudflare.md * Update linode.md * Update README.md * Update README.md * Update linode.md sentence in Italian * v1 The frontend has been completed, along with the .env variables. However, there is an issue of infinite loading thereafter. * Fix email and remove deprecated GitHub passport * Update user_auth_system.md add How to Set Up a Github Authentication * Update .env.example Improved the comment above the GitHub client ID and secret. * Update user_auth_system.md * Update package.json * Remove unnecessary passport GitHub package * fixed conflicts fixed conflicts between Berry-13:main and danny-avila:main in api/server/index.js 45:54 * Delete e -i HEAD~2
104 lines
3.4 KiB
JavaScript
104 lines
3.4 KiB
JavaScript
const express = require('express');
|
|
const session = require('express-session');
|
|
const connectDb = require('../lib/db/connectDb');
|
|
const migrateDb = require('../lib/db/migrateDb');
|
|
const indexSync = require('../lib/db/indexSync');
|
|
const path = require('path');
|
|
const cors = require('cors');
|
|
const routes = require('./routes');
|
|
const errorController = require('./controllers/ErrorController');
|
|
const passport = require('passport');
|
|
const port = process.env.PORT || 3080;
|
|
const host = process.env.HOST || 'localhost';
|
|
const projectPath = path.join(__dirname, '..', '..', 'client');
|
|
|
|
// Init the config and validate it
|
|
const config = require('../../config/loader');
|
|
config.validate(); // Validate the config
|
|
|
|
(async () => {
|
|
await connectDb();
|
|
console.log('Connected to MongoDB');
|
|
await migrateDb();
|
|
await indexSync();
|
|
|
|
const app = express();
|
|
app.use(errorController);
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.use(express.static(path.join(projectPath, 'dist')));
|
|
app.use(express.static(path.join(projectPath, 'public')));
|
|
|
|
app.set('trust proxy', 1); // trust first proxy
|
|
app.use(cors());
|
|
|
|
// OAUTH
|
|
app.use(passport.initialize());
|
|
require('../strategies/jwtStrategy');
|
|
require('../strategies/localStrategy');
|
|
if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) {
|
|
require('../strategies/googleStrategy');
|
|
}
|
|
if (process.env.FACEBOOK_CLIENT_ID && process.env.FACEBOOK_CLIENT_SECRET) {
|
|
require('../strategies/facebookStrategy');
|
|
}
|
|
if (process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET) {
|
|
require('../strategies/githubStrategy');
|
|
}
|
|
if (process.env.OPENID_CLIENT_ID && process.env.OPENID_CLIENT_SECRET &&
|
|
process.env.OPENID_ISSUER && process.env.OPENID_SCOPE &&
|
|
process.env.OPENID_SESSION_SECRET) {
|
|
app.use(session({
|
|
secret: process.env.OPENID_SESSION_SECRET,
|
|
resave: false,
|
|
saveUninitialized: false
|
|
}));
|
|
app.use(passport.session());
|
|
require('../strategies/openidStrategy');
|
|
}
|
|
app.use('/oauth', routes.oauth);
|
|
// api endpoint
|
|
app.use('/api/auth', routes.auth);
|
|
app.use('/api/user', routes.user);
|
|
app.use('/api/search', routes.search);
|
|
app.use('/api/ask', routes.ask);
|
|
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/plugins', routes.plugins);
|
|
app.use('/api/config', routes.config);
|
|
|
|
// static files
|
|
app.get('/*', function (req, res) {
|
|
res.sendFile(path.join(projectPath, 'dist', 'index.html'));
|
|
});
|
|
|
|
app.listen(port, host, () => {
|
|
if (host == '0.0.0.0')
|
|
console.log(
|
|
`Server listening on all interface at port ${port}. Use http://localhost:${port} to access it`
|
|
);
|
|
else
|
|
console.log(`Server listening at http://${host == '0.0.0.0' ? 'localhost' : host}:${port}`);
|
|
});
|
|
})();
|
|
|
|
let messageCount = 0;
|
|
process.on('uncaughtException', (err) => {
|
|
if (!err.message.includes('fetch failed')) {
|
|
console.error('There was an uncaught error:');
|
|
console.error(err);
|
|
}
|
|
|
|
if (err.message.includes('fetch failed')) {
|
|
if (messageCount === 0) {
|
|
console.error('Meilisearch error, search will be disabled');
|
|
messageCount++;
|
|
}
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
});
|