mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-29 13:32:30 +02:00
37 lines
851 B
JavaScript
37 lines
851 B
JavaScript
const { writeFileSync, existsSync } = require('fs')
|
|
const { join } = require('path')
|
|
const crypto = require('crypto')
|
|
|
|
initEnvFile()
|
|
runMigrations()
|
|
.then(startServer)
|
|
|
|
function initEnvFile () {
|
|
const envPath = join(__dirname, '..', '.env')
|
|
const envExists = existsSync(envPath)
|
|
if (!envExists) {
|
|
const configVars = []
|
|
configVars.push({
|
|
name: 'DATABASE_URL',
|
|
value: join(__dirname, '..', 'futurebit.sqlite')
|
|
})
|
|
configVars.push({
|
|
name: 'APP_SECRET',
|
|
value: crypto.randomBytes(64).toString('hex')
|
|
})
|
|
const envFile = configVars
|
|
.map(({ name, value }) => `${name}=${value}`)
|
|
.join('\n') + '\n'
|
|
writeFileSync(envPath, envFile)
|
|
}
|
|
}
|
|
|
|
async function runMigrations () {
|
|
const { knex } = require('./db')
|
|
await knex.migrate.latest()
|
|
}
|
|
|
|
function startServer () {
|
|
require('./server')
|
|
}
|