mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 16:33:23 +08:00
d37333be89
* refactor: removed unused subscription code
* refactor: removed management api's
* refactor: cleanup of connections
* refactor: refactored comments edge
* refactor: simplified connection resolving
* feat: added story connection edge
* fix: added story index
* feat: added user pagination and user edge
* fix: added filter to comment query
* fix: removed unused resolvers
* fix: creating a comment reply should require auth
* refactor: cleanup of graph files
* feat: removed display name, made username non-unique
* fix: fixed tests
* fix: fixed tests
* fix: added more api docs
* fix: fixed bug with installer
* refactor: fixes and updates
* fix: added linting for graphql, fixed schema
* feat: added docker build tests
* fix: upped output timeout
* fix: fixed stacktraces in production builds
* fix: removed `git add`
- `git add` was causing issues with
partial staged changs on files
* feat: improved error messaging for auth
* refactor: cleaned up queue names
* fix: merge error
100 lines
2.5 KiB
TypeScript
100 lines
2.5 KiB
TypeScript
import dotenv from "dotenv";
|
|
import sourceMapSupport from "source-map-support";
|
|
|
|
// Configure the source map support so stack traces will reference the source
|
|
// files rather than the transpiled code.
|
|
sourceMapSupport.install({
|
|
environment: "node",
|
|
});
|
|
|
|
// Apply all the configuration provided in the .env file if it isn't already in
|
|
// the environment.
|
|
dotenv.config();
|
|
|
|
// Makes the script crash on unhandled rejections instead of silently
|
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
// terminate the Node.js process with a non-zero exit code.
|
|
process.on("unhandledRejection", err => {
|
|
throw err;
|
|
});
|
|
|
|
import express from "express";
|
|
import throng from "throng";
|
|
|
|
import createTalk from "./core";
|
|
import Server from "./core/server";
|
|
import logger from "./core/server/logger";
|
|
|
|
// Create the app that will serve as the mounting point for the Talk Server.
|
|
const app = express();
|
|
|
|
// worker will start the worker process.
|
|
async function worker(server: Server) {
|
|
try {
|
|
logger.debug("started server worker");
|
|
|
|
// Start the server.
|
|
await server.start(app);
|
|
} catch (err) {
|
|
logger.error({ err }, "can not start server in worker mode");
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
// master will start the master process.
|
|
async function master(server: Server) {
|
|
const workerCount = server.config.get("concurrency");
|
|
logger.debug({ workerCount }, "spawning workers to handle traffic");
|
|
|
|
try {
|
|
logger.debug("started server master");
|
|
|
|
// Process jobs.
|
|
await server.process();
|
|
} catch (err) {
|
|
logger.error({ err }, "can not start server in master mode");
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
// bootstrap will create a new Talk server, and start it up.
|
|
async function bootstrap() {
|
|
try {
|
|
logger.debug("starting bootstrap");
|
|
|
|
// Create the server instance.
|
|
const server = await createTalk();
|
|
|
|
// Determine the number of workers.
|
|
const workerCount = server.config.get("concurrency");
|
|
|
|
// Connect the server to databases.
|
|
await server.connect();
|
|
|
|
if (workerCount === 1) {
|
|
logger.debug(
|
|
{ workerCount },
|
|
"not utilizing cluster as concurrency level is 1"
|
|
);
|
|
|
|
// Start processing jobs.
|
|
await server.process();
|
|
|
|
// Start the server.
|
|
await server.start(app);
|
|
} else {
|
|
// Launch the server start within throng.
|
|
throng({
|
|
workers: workerCount,
|
|
start: () => worker(server),
|
|
master: () => master(server),
|
|
});
|
|
}
|
|
} catch (err) {
|
|
logger.error({ err }, "can not bootstrap server");
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
bootstrap();
|