代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/mongo-express 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env node
'use strict';
const clc = require('cli-color');
const csrf = require('csurf');
const commander = require('commander');
const express = require('express');
const fs = require('fs');
const https = require('https');
const updateNotifier = require('update-notifier');
const middleware = require('./lib/middleware');
const utils = require('./lib/utils');
const pkg = require('./package.json');
const app = express();
const notifier = updateNotifier({ pkg });
let config;
let defaultPort = 80;
let server = app;
let sslOptions;
// Notify of any updates
notifier.notify();
try {
// eslint-disable-next-line import/no-unresolved
config = utils.deepmerge(require('./config.default'), require('./config'));
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.log('No custom config.js found, loading config.default.js');
} else {
console.error(clc.red('Unable to load config.js!'));
console.error(clc.red('Error is:'));
console.log(clc.red(e));
process.exit(1);
}
config = require('./config.default');
}
if (config.options.console) {
console.log('Welcome to mongo-express');
console.log('------------------------');
console.log('\n');
}
commander
.version(require('./package').version)
.option('-U, --url <url>', 'connection string url')
.option('-H, --host <host>', 'hostname or address of the db(deprecated)')
.option('-P, --dbport <host>', 'port of the db(deprecated)')
.option('-u, --username <username>', 'username for authentication(deprecated)')
.option('-p, --password <password>', 'password for authentication(deprecated)')
.option('-a, --admin', 'enable authentication as admin')
.option('-d, --database <database>', 'authenticate to database')
.option('--port <port>', 'listen on specified port')
.parse(process.argv);
if (commander.username && commander.password) {
config.mongodb.admin = !!commander.admin;
if (commander.admin) {
config.mongodb.adminUsername = commander.username;
config.mongodb.adminPassword = commander.password;
} else {
const user = {
database: commander.database,
username: commander.username,
password: commander.password,
};
for (const key in user) {
if (!user[key]) {
commander.help();
}
}
config.mongodb.auth[0] = user;
}
config.useBasicAuth = false;
}
if (commander.url) {
config.mongodb.connectionString = commander.url;
if (commander.admin) {
config.mongodb.admin = true;
}
}
config.mongodb.server = commander.host || config.mongodb.server;
config.mongodb.port = commander.dbport || config.mongodb.port;
config.site.port = commander.port || config.site.port;
if (!config.site.baseUrl) {
console.error('Please specify a baseUrl in your config. Using "/" for now.');
config.site.baseUrl = '/';
}
async function bootstrap() {
const resolvedMiddleware = await middleware(config);
app.use(config.site.baseUrl, resolvedMiddleware);
app.use(config.site.baseUrl, csrf());
if (config.site.sslEnabled) {
defaultPort = 443;
sslOptions = {
key: fs.readFileSync(config.site.sslKey),
cert: fs.readFileSync(config.site.sslCert),
};
server = https.createServer(sslOptions, app);
}
const addressString = (config.site.sslEnabled ? 'https://' : 'http://') + (config.site.host || '0.0.0.0') + ':' + (config.site.port || defaultPort);
server.listen(config.site.port, config.site.host, function () {
if (config.options.console) {
console.log('Mongo Express server listening', 'at ' + addressString);
if (!config.site.host || config.site.host === '0.0.0.0') {
console.error(clc.red('Server is open to allow connections from anyone (0.0.0.0)'));
}
if (config.basicAuth.username === 'admin' && config.basicAuth.password === 'pass') {
console.error(clc.red('basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!'));
}
}
})
.on('error', function (e) {
if (e.code === 'EADDRINUSE') {
console.log();
console.error(clc.red('Address ' + addressString + ' already in use! You need to pick a different host and/or port.'));
console.log('Maybe mongo-express is already running?');
}
console.log();
console.log('If you are still having trouble, try Googling for the key parts of the following error object before posting an issue');
console.log(JSON.stringify(e));
return process.exit(1);
});
}
bootstrap();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。