1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/main.mjs

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-06-23 00:32:51 +08:00
import fs from 'fs';
import { join, dirname } from 'path';
import { Low, JSONFile } from 'lowdb';
import { fileURLToPath } from 'url';
import { CoreApp } from 'hackchat-server';
// required file paths
const SessionLocation = './session.key';
const SaltLocation = './salt.key';
const AppConfigLocation = './config.json';
// verify required files exist
if (fs.existsSync(SessionLocation) === false) {
throw Error('Missing session key, you may need to run: npm run config');
}
if (fs.existsSync(SaltLocation) === false) {
throw Error('Missing salt key, you may need to run: npm run config');
}
if (fs.existsSync(AppConfigLocation) === false) {
throw Error('Missing config, you may need to run: npm run config');
}
// build main hack chat server
const server = new CoreApp({
configPath: './.hcserver.json',
logErrDetailed: true,
lang: 'en',
});
// load sessoin key data
server.sessionKey = fs.readFileSync(SessionLocation);
// load salt key data
server.saltKey = fs.readFileSync(SaltLocation);
// load the configuration data
const adapter = new JSONFile(AppConfigLocation);
server.appConfig = new Low(adapter);
await server.appConfig.read();
server.init();
console.log('Websocket server ready');