mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: set cookie to secure and strict
This commit is contained in:
1 parent
ca2a40341c
commit
db16413754
3 files changed
+24
-11
No files matched your search
+21
-9
@@ -23,9 +23,19 @@ function getUrl(key) {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = {
|
function createConfig() {
|
||||||
host: get('HOST', 'localhost'),
|
const isProduction = process.env.NODE_ENV === 'production'
|
||||||
port: get('PORT', 3000),
|
const host = get('HOST', 'localhost')
|
||||||
|
const port = Number(get('PORT', 3000))
|
||||||
|
const baseUrl = get('BASE_URL', `http://${host}:${port}`)
|
||||||
|
const url = new URL(baseUrl)
|
||||||
|
return {
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
baseUrl,
|
||||||
|
domain: url.hostname,
|
||||||
|
protocol: url.protocol,
|
||||||
|
backendUrl: get('BACKEND_URL', baseUrl),
|
||||||
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
||||||
secret: get('SECRET_KEY', ''),
|
secret: get('SECRET_KEY', ''),
|
||||||
isProduction: process.env.NODE_ENV === 'production',
|
isProduction: process.env.NODE_ENV === 'production',
|
||||||
@@ -54,15 +64,17 @@ const config = {
|
|||||||
log: {
|
log: {
|
||||||
path: get('LOG_PATH', '../logs'),
|
path: get('LOG_PATH', '../logs'),
|
||||||
},
|
},
|
||||||
}
|
testing: {
|
||||||
|
enabled: !isProduction && process.env.TESTING === 'true',
|
||||||
config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`)
|
|
||||||
config.backendUrl = get('BACKEND_URL', config.baseUrl)
|
|
||||||
config.testing = {
|
|
||||||
enabled: !config.isProduction && process.env.TESTING === 'true',
|
|
||||||
username: get('TESTING_USERNAME', ''),
|
username: get('TESTING_USERNAME', ''),
|
||||||
password: get('TESTING_PASSWORD', ''),
|
password: get('TESTING_PASSWORD', ''),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = createConfig()
|
||||||
|
|
||||||
|
console.log(config)
|
||||||
|
|
||||||
export function getQuestImage(id) {
|
export function getQuestImage(id) {
|
||||||
return `${config.docker.imagePrefix}${id}`
|
return `${config.docker.imagePrefix}${id}`
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ export default session({
|
|||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
rolling: true,
|
rolling: true,
|
||||||
cookie: {
|
cookie: {
|
||||||
|
domain: config.domain,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: false,
|
secure: config.protocol === 'https:',
|
||||||
sameSite: 'lax',
|
sameSite: 'strict',
|
||||||
maxAge: config.sessionMaxAge,
|
maxAge: config.sessionMaxAge,
|
||||||
},
|
},
|
||||||
store: MongoStore.create({
|
store: MongoStore.create({
|
||||||
|
|||||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 119 KiB |
Reference in new issue
Block a user