mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: cors enabled for desktop mode
This commit is contained in:
13
api/package-lock.json
generated
13
api/package-lock.json
generated
@@ -27,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
"@types/express": "^4.17.12",
|
"@types/express": "^4.17.12",
|
||||||
"@types/jest": "^26.0.24",
|
"@types/jest": "^26.0.24",
|
||||||
"@types/jsonwebtoken": "^8.5.5",
|
"@types/jsonwebtoken": "^8.5.5",
|
||||||
@@ -2205,6 +2206,12 @@
|
|||||||
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
|
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/cors": {
|
||||||
|
"version": "2.8.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
|
||||||
|
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/express": {
|
"node_modules/@types/express": {
|
||||||
"version": "4.17.12",
|
"version": "4.17.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
|
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
|
||||||
@@ -16651,6 +16658,12 @@
|
|||||||
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
|
"integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/cors": {
|
||||||
|
"version": "2.8.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
|
||||||
|
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/express": {
|
"@types/express": {
|
||||||
"version": "4.17.12",
|
"version": "4.17.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
|
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
|
||||||
|
|||||||
@@ -15,24 +15,20 @@
|
|||||||
"lint:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"lint:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
"package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
|
"package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
|
||||||
"exe": "npm run build && cd build && npm run public:copy && npm run web && pkg .",
|
"exe": "npm run build && npm run public:copy && npm run web:copy && pkg .",
|
||||||
"public:copy": "cp -r ../public/ ./public/",
|
"public:copy": "cp -r ./public/ ./build/public/",
|
||||||
"web": "cd .. && npm run web:mkdir && npm run web:copy && cd build",
|
"web:copy": "rimraf web && mkdir web && cp -r ../web/build/ ./web/build/"
|
||||||
"web:mkdir": "rimraf web && mkdir web && mkdir web/build",
|
|
||||||
"web:copy": "cp -r ../web/build/ ./web/build/"
|
|
||||||
},
|
},
|
||||||
"bin": "src/server.js",
|
"bin": "./build/src/server.js",
|
||||||
"pkg": {
|
"pkg": {
|
||||||
"assets": [
|
"assets": [
|
||||||
"public/**/*",
|
"./build/public/**/*",
|
||||||
"../web/build/**/*"
|
"./web/build/**/*"
|
||||||
],
|
],
|
||||||
"targets": [
|
"targets": [
|
||||||
"node16-linux-x64",
|
"node16-macos-x64"
|
||||||
"node16-macos-x64",
|
|
||||||
"node16-win-x64"
|
|
||||||
],
|
],
|
||||||
"outputPath": "../../executables"
|
"outputPath": "../executables"
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"branches": [
|
"branches": [
|
||||||
@@ -57,6 +53,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
"@types/express": "^4.17.12",
|
"@types/express": "^4.17.12",
|
||||||
"@types/jest": "^26.0.24",
|
"@types/jest": "^26.0.24",
|
||||||
"@types/jsonwebtoken": "^8.5.5",
|
"@types/jsonwebtoken": "^8.5.5",
|
||||||
|
|||||||
@@ -981,7 +981,7 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
description: "Trigger a SAS program using it's location in the _program parameter.\r\nEnable debugging using the _debug parameter.\r\nAdditional URL parameters are turned into SAS macro variables.\r\nAny files provided are placed into the session and\r\ncorresponding _WEBIN_XXX variables are created."
|
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
||||||
summary: 'Execute Stored Program, return raw content'
|
summary: 'Execute Stored Program, return raw content'
|
||||||
tags:
|
tags:
|
||||||
- STP
|
- STP
|
||||||
@@ -1005,7 +1005,7 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
||||||
description: "Trigger a SAS program using it's location in the _program parameter.\r\nEnable debugging using the _debug parameter.\r\nAdditional URL parameters are turned into SAS macro variables.\r\nAny files provided are placed into the session and\r\ncorresponding _WEBIN_XXX variables are created."
|
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
||||||
summary: 'Execute Stored Program, return JSON'
|
summary: 'Execute Stored Program, return JSON'
|
||||||
tags:
|
tags:
|
||||||
- STP
|
- STP
|
||||||
|
|||||||
@@ -2,15 +2,22 @@ import path from 'path'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import morgan from 'morgan'
|
import morgan from 'morgan'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
import cors from 'cors'
|
||||||
|
|
||||||
import webRouter from './routes/web'
|
import webRouter from './routes/web'
|
||||||
import apiRouter from './routes/api'
|
import apiRouter from './routes/api'
|
||||||
import { getWebBuildFolderPath } from './utils'
|
import { getWebBuildFolderPath } from './utils'
|
||||||
import { connectDB } from './routes/api/auth'
|
import { connectDB } from './routes/api/auth'
|
||||||
|
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
const cors=require('cors')
|
const { MODE } = process.env
|
||||||
app.use(cors())
|
if (MODE?.trim() !== 'server') {
|
||||||
|
console.log('All CORS Requests are enabled')
|
||||||
|
app.use(cors({ credentials: true, origin: 'http://localhost:3000' }))
|
||||||
|
}
|
||||||
|
|
||||||
app.use(express.json({ limit: '50mb' }))
|
app.use(express.json({ limit: '50mb' }))
|
||||||
app.use(morgan('tiny'))
|
app.use(morgan('tiny'))
|
||||||
@@ -22,6 +29,4 @@ app.use(express.json({ limit: '50mb' }))
|
|||||||
|
|
||||||
app.use(express.static(getWebBuildFolderPath()))
|
app.use(express.static(getWebBuildFolderPath()))
|
||||||
|
|
||||||
dotenv.config()
|
|
||||||
|
|
||||||
export default connectDB().then(() => app)
|
export default connectDB().then(() => app)
|
||||||
|
|||||||
@@ -7,16 +7,17 @@ const headers = {
|
|||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
const baseUrl =
|
||||||
|
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
|
||||||
const getAuthCode = async (credentials: any) => {
|
const getAuthCode = async (credentials: any) => {
|
||||||
return fetch('/SASjsApi/auth/authorize', {
|
return fetch(`${baseUrl}/SASjsApi/auth/authorize`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(credentials)
|
body: JSON.stringify(credentials)
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
const getTokens = async (payload: any) => {
|
const getTokens = async (payload: any) => {
|
||||||
return fetch('/SASjsApi/auth/token', {
|
return fetch(`${baseUrl}/SASjsApi/auth/token`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
|
|||||||
@@ -43,15 +43,18 @@ export default function useTokens() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const baseUrl = 'http://localhost:5000'
|
const baseUrl =
|
||||||
// const isAbsoluteURLRegex = /^(?:\w+:)\/\//
|
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
|
||||||
|
|
||||||
|
const isAbsoluteURLRegex = /^(?:\w+:)\/\//
|
||||||
|
|
||||||
const setAxiosRequestHeader = (accessToken: string) => {
|
const setAxiosRequestHeader = (accessToken: string) => {
|
||||||
axios.interceptors.request.use(function (config: any) {
|
axios.interceptors.request.use(function (config) {
|
||||||
// if (!isAbsoluteURLRegex.test(config.url)) {
|
if (baseUrl && !isAbsoluteURLRegex.test(config.url as string)) {
|
||||||
// config.url = baseUrl + config.url
|
config.url = baseUrl + config.url
|
||||||
// }
|
}
|
||||||
config.headers.Authorization = `Bearer ${accessToken}`
|
config.headers!['Authorization'] = `Bearer ${accessToken}`
|
||||||
|
config.withCredentials = true
|
||||||
|
|
||||||
return config
|
return config
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user