mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-01 16:31:25 +03:00
fix: http, improve env
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
/* eslint-disable no-console */
|
||||
require('dotenv').config();
|
||||
const fs = require('fs-extra');
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const { short } = require('leeks.js');
|
||||
|
||||
function log(...strings) {
|
||||
console.log(short('&9[postinstall]&r'), ...strings);
|
||||
}
|
||||
|
||||
async function npx(cmd) {
|
||||
console.log(`[postinstall] > ${cmd}`);
|
||||
log(`> ${cmd}`);
|
||||
const {
|
||||
stderr,
|
||||
stdout,
|
||||
@@ -17,14 +23,14 @@ const providers = ['mysql', 'postgresql', 'sqlite'];
|
||||
const provider = process.env.DB_PROVIDER;
|
||||
|
||||
if (!provider) {
|
||||
console.log('[postinstall] environment not set, exiting.');
|
||||
log('environment not set, exiting.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!providers.includes(provider)) throw new Error(`DB_PROVIDER must be one of: ${providers}`);
|
||||
|
||||
console.log(`[postinstall] provider=${provider}`);
|
||||
console.log(`[postinstall] copying ${provider} schema & migrations`);
|
||||
log(`provider=${provider}`);
|
||||
log(`copying ${provider} schema & migrations`);
|
||||
|
||||
if (!fs.existsSync('./prisma')) fs.mkdirSync('./prisma');
|
||||
fs.copySync(`./db/${provider}`, './prisma'); // copy schema & migrations
|
||||
|
@@ -1,5 +1,11 @@
|
||||
/* eslint-disable no-console */
|
||||
const { randomBytes } = require('crypto');
|
||||
const fs = require('fs');
|
||||
const { short } = require('leeks.js');
|
||||
|
||||
function log (...strings) {
|
||||
console.log(short('&9[preinstall]&r'), ...strings);
|
||||
}
|
||||
|
||||
const env = {
|
||||
DB_CONNECTION_URL: '',
|
||||
@@ -7,18 +13,22 @@ const env = {
|
||||
DISCORD_SECRET: '',
|
||||
DISCORD_TOKEN: '',
|
||||
ENCRYPTION_KEY: randomBytes(24).toString('hex'),
|
||||
HTTP_BIND: 8080,
|
||||
HTTP_EXTERNAL: 'http://localhost:8080',
|
||||
HTTP_EXTERNAL: 'http://127.0.0.1:8080',
|
||||
HTTP_HOST: '127.0.0.1',
|
||||
HTTP_PORT: 8080,
|
||||
HTTP_TRUST_PROXY: false,
|
||||
OVERRIDE_ARCHIVE: '',
|
||||
PUBLIC_BOT: false,
|
||||
SETTINGS_BIND: 8888,
|
||||
SETTINGS_HOST: '127.0.0.1',
|
||||
SETTINGS_PORT: 8169,
|
||||
SUPER: '319467558166069248',
|
||||
};
|
||||
|
||||
// check DISCORD_TOKEN because we don't want to force use of the .env file
|
||||
if (!process.env.DISCORD_TOKEN && !fs.existsSync('./.env')) {
|
||||
console.log('[preinstall] Generating ENCRYPTION_KEY');
|
||||
// check ENCRYPTION_KEY because we don't want to force use of the .env file
|
||||
if (!process.env.ENCRYPTION_KEY && !fs.existsSync('./.env')) {
|
||||
log('generating ENCRYPTION_KEY');
|
||||
fs.writeFileSync('./.env', Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n'));
|
||||
console.log('[preinstall] Created .env file');
|
||||
log('created .env file');
|
||||
} else {
|
||||
console.log('[preinstall] Nothing to do');
|
||||
log('nothing to do');
|
||||
}
|
Reference in New Issue
Block a user