1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-09 07:20:05 +00:00

fix: refactored + removed unused package

This commit is contained in:
Saad Jutt
2022-02-15 04:04:38 +05:00
parent de47d78a00
commit d7e1aca7e3
6 changed files with 109 additions and 8570 deletions

View File

@@ -1,8 +1,7 @@
import path from 'path'
import { createServer } from 'https'
import { readFile } from '@sasjs/utils'
import appPromise from './app'
import { getCertificates } from './utils'
appPromise.then(async (app) => {
const protocol = process.env.PROTOCOL ?? 'http'
@@ -25,16 +24,3 @@ appPromise.then(async (app) => {
})
}
})
const getCertificates = async () => {
const privkey = process.env.PRIVATE_KEY ?? 'privkey.pem'
const fullchain = process.env.FULL_CHAIN ?? 'fullchain.pem'
const keyPath = path.join(process.cwd(), privkey)
const certPath = path.join(process.cwd(), fullchain)
const key = await readFile(keyPath)
const cert = await readFile(certPath)
return { key, cert }
}

View File

@@ -0,0 +1,33 @@
import path from 'path'
import { fileExists, getString, readFile } from '@sasjs/utils'
export const getCertificates = async () => {
const { PRIVATE_KEY, FULL_CHAIN } = process.env
const keyPath = PRIVATE_KEY ?? (await getFileInput('Private Key (PEM)'))
const certPath = FULL_CHAIN ?? (await getFileInput('Full Chain (PEM)'))
const key = await readFile(keyPath)
const cert = await readFile(certPath)
return { key, cert }
}
const getFileInput = async (filename: string): Promise<string> => {
const validator = async (filePath: string) => {
if (!filePath) return `Path to ${filename} is required.`
if (!(await fileExists(path.join(process.cwd(), filePath)))) {
return 'No file found at provided path.'
}
return true
}
const targetName = await getString(
`Please enter path to ${filename} (relative path): `,
validator
)
return targetName
}

View File

@@ -3,6 +3,7 @@ export * from './file'
export * from './generateAccessToken'
export * from './generateAuthCode'
export * from './generateRefreshToken'
export * from './getCertificates'
export * from './getDesktopFields'
export * from './removeTokensInDB'
export * from './saveTokensInDB'