mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: release should also has https protocol
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
MODE=[desktop|server] default considered as desktop
|
MODE=[desktop|server] default considered as desktop
|
||||||
CORS=[disable|enable] default considered as disable
|
CORS=[disable|enable] default considered as disable
|
||||||
|
PROTOCOL=[http|https] default considered as http
|
||||||
|
PRIVATE_KEY=privkey.pem
|
||||||
|
FULL_CHAIN=fullchain.pem
|
||||||
PORT=[5000] default value is 5000
|
PORT=[5000] default value is 5000
|
||||||
PORT_WEB=[port for sasjs web component(react)] default value is 3000
|
PORT_WEB=[port for sasjs web component(react)] default value is 3000
|
||||||
ACCESS_TOKEN_SECRET=<secret>
|
ACCESS_TOKEN_SECRET=<secret>
|
||||||
|
|||||||
@@ -6,10 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"initial": "npm run swagger && npm run compileSysInit",
|
"initial": "npm run swagger && npm run compileSysInit",
|
||||||
"prestart": "npm run initial",
|
"prestart": "npm run initial",
|
||||||
"prestart:prod": "npm run initial",
|
|
||||||
"prebuild": "npm run initial",
|
"prebuild": "npm run initial",
|
||||||
"start": "nodemon ./src/server.ts",
|
"start": "nodemon ./src/server.ts",
|
||||||
"start:prod": "nodemon ./src/prod-server.ts",
|
|
||||||
"build": "rimraf build && tsc",
|
"build": "rimraf build && tsc",
|
||||||
"swagger": "tsoa spec",
|
"swagger": "tsoa spec",
|
||||||
"semantic-release": "semantic-release -d",
|
"semantic-release": "semantic-release -d",
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import path from 'path'
|
|
||||||
import { readFileSync } from 'fs'
|
|
||||||
import * as https from 'https'
|
|
||||||
import appPromise from './app'
|
|
||||||
|
|
||||||
const keyPath = path.join('..', 'certificates', 'privkey.pem')
|
|
||||||
const certPath = path.join('..', 'certificates', 'fullchain.pem')
|
|
||||||
|
|
||||||
const key = readFileSync(keyPath)
|
|
||||||
const cert = readFileSync(certPath)
|
|
||||||
|
|
||||||
appPromise.then((app) => {
|
|
||||||
const httpsServer = https.createServer({ key, cert }, app)
|
|
||||||
|
|
||||||
const sasJsPort = process.env.PORT ?? 5000
|
|
||||||
httpsServer.listen(sasJsPort, () => {
|
|
||||||
console.log(
|
|
||||||
`⚡️[server]: Server is running at https://localhost:${sasJsPort}`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,10 +1,40 @@
|
|||||||
|
import path from 'path'
|
||||||
|
import { createServer } from 'https'
|
||||||
|
import { readFile } from '@sasjs/utils'
|
||||||
|
|
||||||
import appPromise from './app'
|
import appPromise from './app'
|
||||||
|
|
||||||
appPromise.then((app) => {
|
appPromise.then(async (app) => {
|
||||||
|
const protocol = process.env.PROTOCOL ?? 'http'
|
||||||
const sasJsPort = process.env.PORT ?? 5000
|
const sasJsPort = process.env.PORT ?? 5000
|
||||||
app.listen(sasJsPort, () => {
|
|
||||||
console.log(
|
if (protocol !== 'https') {
|
||||||
`⚡️[server]: Server is running at http://localhost:${sasJsPort}`
|
app.listen(sasJsPort, () => {
|
||||||
)
|
console.log(
|
||||||
})
|
`⚡️[server]: Server is running at http://localhost:${sasJsPort}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const { key, cert } = await getCertificates()
|
||||||
|
|
||||||
|
const httpsServer = createServer({ key, cert }, app)
|
||||||
|
httpsServer.listen(sasJsPort, () => {
|
||||||
|
console.log(
|
||||||
|
`⚡️[server]: Server is running at https://localhost:${sasJsPort}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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 }
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"server": "npm run server:prepare && npm run server:start",
|
"server": "npm run server:prepare && npm run server:start",
|
||||||
"server:prepare": "cd web && npm ci && npm run build && cd ../api && npm ci && cd ..",
|
"server:prepare": "cd web && npm ci && npm run build && cd ../api && npm ci && cd ..",
|
||||||
"server:start": "cd api && npm run start:prod",
|
"server:start": "cd api && npm run start",
|
||||||
"release": "standard-version",
|
"release": "standard-version",
|
||||||
"lint-api:fix": "npx prettier --write \"api/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"lint-api:fix": "npx prettier --write \"api/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
"lint-api": "npx prettier --check \"api/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"lint-api": "npx prettier --check \"api/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
|
|||||||
Reference in New Issue
Block a user