-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2dd79
commit 40ef460
Showing
16 changed files
with
6,198 additions
and
5,084 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,49 @@ | |
* @Author: [email protected] | ||
* @Date: 2022-11-15 14:48:43 | ||
* @LastEditors: [email protected] | ||
* @LastEditTime: 2022-11-17 11:15:40 | ||
* @LastEditTime: 2024-08-10 15:25:45 | ||
* @Description: | ||
*/ | ||
const express = require("express"); | ||
const cors = require('cors'); | ||
const compression = require('compression'); | ||
const session = require('express-session') | ||
const session = require('express-session'); | ||
|
||
function parseOrigin(originEnv) { | ||
if (originEnv === 'true') { | ||
return true; | ||
} else if (originEnv === 'false') { | ||
return false; | ||
} else if (/^\/.*\/$/.test(originEnv)) { // 正则表达式检查 | ||
return new RegExp(originEnv.slice(1, -1)); // 去掉两边的斜杠 | ||
} else if (originEnv.startsWith('[') && originEnv.endsWith(']')) { // 数组检查 | ||
const originsArray = JSON.parse(originEnv); | ||
return originsArray.map(item => { | ||
if (typeof item === 'string') { | ||
return item; | ||
} else if (/^\/.*\/$/.test(item)) { | ||
return new RegExp(item.slice(1, -1)); | ||
} else { | ||
throw new Error('Invalid origin value in array'); | ||
} | ||
}); | ||
} else if (typeof originEnv === 'string') { | ||
return originEnv; | ||
} else { | ||
throw new Error('Invalid origin value'); | ||
} | ||
} | ||
|
||
const originEnv = process.env.STEEDOS_CORS_ORIGIN; | ||
let origin = true; | ||
try { | ||
origin = parseOrigin(originEnv); | ||
console.log('Parsed origin:', origin); | ||
} catch (error) { | ||
console.error('Error parsing origin:', error.message); | ||
} | ||
|
||
console.log(`origin----<`, origin) | ||
|
||
class ExpressAppStatic{ | ||
app = null; | ||
|
@@ -19,7 +55,7 @@ class ExpressAppStatic{ | |
this.router = express.Router(); | ||
// 读取环境变量、配置文件, 启动端口, 控制中间件 | ||
const app = express(); | ||
app.use(cors({origin: true, credentials: true})) | ||
app.use(cors({origin: origin, credentials: true})) | ||
app.use(compression()); | ||
app.use(session({ | ||
secret: process.env.STEEDOS_SESSION_SECRET || 'steedos', | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.