mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 18:53:08 +02:00
Use accesses
This commit is contained in:
parent
45034d6426
commit
0bba9b1e6c
3 changed files with 37 additions and 29 deletions
|
@ -56,6 +56,10 @@ interface Source {
|
||||||
secretKey: string;
|
secretKey: string;
|
||||||
};
|
};
|
||||||
accesslog?: string;
|
accesslog?: string;
|
||||||
|
accesses?: {
|
||||||
|
enable: boolean;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
twitter?: {
|
twitter?: {
|
||||||
consumer_key: string;
|
consumer_key: string;
|
||||||
consumer_secret: string;
|
consumer_secret: string;
|
||||||
|
|
51
src/index.ts
51
src/index.ts
|
@ -11,26 +11,22 @@ import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as cluster from 'cluster';
|
import * as cluster from 'cluster';
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
import Logger from './utils/logger';
|
|
||||||
import * as chalk from 'chalk';
|
import * as chalk from 'chalk';
|
||||||
//import portUsed = require('tcp-port-used');
|
//import portUsed = require('tcp-port-used');
|
||||||
import isRoot = require('is-root');
|
import isRoot = require('is-root');
|
||||||
|
import { master } from 'accesses';
|
||||||
|
|
||||||
|
import Logger from './utils/logger';
|
||||||
import ProgressBar from './utils/cli/progressbar';
|
import ProgressBar from './utils/cli/progressbar';
|
||||||
import EnvironmentInfo from './utils/environmentInfo';
|
import EnvironmentInfo from './utils/environmentInfo';
|
||||||
import MachineInfo from './utils/machineInfo';
|
import MachineInfo from './utils/machineInfo';
|
||||||
import DependencyInfo from './utils/dependencyInfo';
|
import DependencyInfo from './utils/dependencyInfo';
|
||||||
|
|
||||||
import { path as configPath } from './config';
|
import { Config, path as configPath } from './config';
|
||||||
import loadConfig from './config';
|
import loadConfig from './config';
|
||||||
|
|
||||||
const clusterLog = debug('misskey:cluster');
|
const clusterLog = debug('misskey:cluster');
|
||||||
|
|
||||||
enum InitResult {
|
|
||||||
Success,
|
|
||||||
Warn,
|
|
||||||
Failure
|
|
||||||
}
|
|
||||||
|
|
||||||
process.title = 'Misskey';
|
process.title = 'Misskey';
|
||||||
|
|
||||||
// Start app
|
// Start app
|
||||||
|
@ -51,27 +47,26 @@ function main() {
|
||||||
* Init master process
|
* Init master process
|
||||||
*/
|
*/
|
||||||
async function masterMain() {
|
async function masterMain() {
|
||||||
let initResult: InitResult;
|
let config: Config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// initialize app
|
// initialize app
|
||||||
initResult = await init();
|
config = await init();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (initResult) {
|
if (config == null) {
|
||||||
case InitResult.Success:
|
Logger.error(chalk.red('Fatal error occurred during initializing :('));
|
||||||
Logger.info(chalk.green('Successfully initialized :)'));
|
process.exit();
|
||||||
break;
|
}
|
||||||
case InitResult.Warn:
|
|
||||||
Logger.warn(chalk.yellow('Initialized with some problem(s) :|'));
|
Logger.info(chalk.green('Successfully initialized :)'));
|
||||||
break;
|
|
||||||
case InitResult.Failure:
|
// Init accesses
|
||||||
Logger.error(chalk.red('Fatal error occurred during initializing :('));
|
if (config.accesses && config.accesses.enable) {
|
||||||
process.exit();
|
master();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnWorkers(() => {
|
spawnWorkers(() => {
|
||||||
|
@ -90,9 +85,7 @@ function workerMain() {
|
||||||
/**
|
/**
|
||||||
* Init app
|
* Init app
|
||||||
*/
|
*/
|
||||||
async function init() {
|
async function init(): Promise<Config> {
|
||||||
let warn = false;
|
|
||||||
|
|
||||||
Logger.info('Welcome to Misskey!');
|
Logger.info('Welcome to Misskey!');
|
||||||
Logger.info(chalk.bold('Misskey <aoi>'));
|
Logger.info(chalk.bold('Misskey <aoi>'));
|
||||||
Logger.info('Initializing...');
|
Logger.info('Initializing...');
|
||||||
|
@ -104,7 +97,7 @@ async function init() {
|
||||||
let configLogger = new Logger('Config');
|
let configLogger = new Logger('Config');
|
||||||
if (!fs.existsSync(configPath)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
configLogger.error('Configuration not found');
|
configLogger.error('Configuration not found');
|
||||||
return InitResult.Failure;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
@ -114,14 +107,14 @@ async function init() {
|
||||||
|
|
||||||
if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
|
if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
|
||||||
Logger.error('You need root privileges to listen on port below 1024 on Linux');
|
Logger.error('You need root privileges to listen on port below 1024 on Linux');
|
||||||
return InitResult.Failure;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a port is being used
|
// Check if a port is being used
|
||||||
/* https://github.com/stdarg/tcp-port-used/issues/3
|
/* https://github.com/stdarg/tcp-port-used/issues/3
|
||||||
if (await portUsed.check(config.port)) {
|
if (await portUsed.check(config.port)) {
|
||||||
Logger.error(`Port ${config.port} is already used`);
|
Logger.error(`Port ${config.port} is already used`);
|
||||||
return InitResult.Failure;
|
return null;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -133,10 +126,10 @@ async function init() {
|
||||||
db.close();
|
db.close();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
mongoDBLogger.error(e);
|
mongoDBLogger.error(e);
|
||||||
return InitResult.Failure;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return warn ? InitResult.Warn : InitResult.Success;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnWorkers(onComplete: any) {
|
function spawnWorkers(onComplete: any) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import * as https from 'https';
|
||||||
import * as cluster from 'cluster';
|
import * as cluster from 'cluster';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import * as morgan from 'morgan';
|
import * as morgan from 'morgan';
|
||||||
|
import Accesses from 'accesses';
|
||||||
import vhost = require('vhost');
|
import vhost = require('vhost');
|
||||||
|
|
||||||
import config from './conf';
|
import config from './conf';
|
||||||
|
@ -20,6 +21,16 @@ app.disable('x-powered-by');
|
||||||
app.set('trust proxy', 'loopback');
|
app.set('trust proxy', 'loopback');
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
|
if (config.accesses && config.accesses.enable) {
|
||||||
|
const accesses = new Accesses({
|
||||||
|
appName: 'Misskey',
|
||||||
|
port: config.accesses.port,
|
||||||
|
hashIp: true
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(accesses.express);
|
||||||
|
}
|
||||||
|
|
||||||
app.use(morgan(process.env.NODE_ENV == 'production' ? 'combined' : 'dev', {
|
app.use(morgan(process.env.NODE_ENV == 'production' ? 'combined' : 'dev', {
|
||||||
// create a write stream (in append mode)
|
// create a write stream (in append mode)
|
||||||
stream: config.accesslog ? fs.createWriteStream(config.accesslog) : null
|
stream: config.accesslog ? fs.createWriteStream(config.accesslog) : null
|
||||||
|
|
Loading…
Reference in a new issue