@ossy/app 0.13.4 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/proxy-internal.js +35 -11
- package/cli/server.js +7 -2
- package/package.json +2 -2
package/cli/proxy-internal.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** Node/Express can join duplicate workspace headers as `id, id` — API expects a single id. */
|
|
2
|
+
function normalizeWorkspaceIdHeader (value) {
|
|
3
|
+
if (!value || value === 'undefined') return undefined
|
|
4
|
+
const first = String(value).split(',')[0]?.trim()
|
|
5
|
+
return first || undefined
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
export function ProxyInternal() {
|
|
2
9
|
return (req, res, next) => {
|
|
3
10
|
|
|
@@ -48,18 +55,18 @@ export function ProxyInternal() {
|
|
|
48
55
|
|
|
49
56
|
const domain = process.env.OSSY_API_URL || 'https://api.ossy.se'
|
|
50
57
|
const url = `${domain}${req.originalUrl?.replace('/@ossy', '/api/v0')}`
|
|
51
|
-
const
|
|
52
|
-
const workspaceId =
|
|
53
|
-
|
|
58
|
+
const forwardedHeaders = JSON.parse(JSON.stringify(req.headers))
|
|
59
|
+
const workspaceId = normalizeWorkspaceIdHeader(req.get('workspaceId'))
|
|
60
|
+
|
|
54
61
|
if (workspaceId) {
|
|
55
|
-
|
|
62
|
+
forwardedHeaders['workspaceid'] = workspaceId
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
console.log(`[@ossy/app][proxy] workspaceId ${workspaceId}`)
|
|
59
|
-
|
|
66
|
+
|
|
60
67
|
const request = {
|
|
61
68
|
method: req.method,
|
|
62
|
-
headers:
|
|
69
|
+
headers: forwardedHeaders
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
if (!['GET', 'HEAD'].includes(req.method)) {
|
|
@@ -74,11 +81,28 @@ export function ProxyInternal() {
|
|
|
74
81
|
});
|
|
75
82
|
|
|
76
83
|
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
77
|
-
return response.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
return response.text().then((text) => {
|
|
85
|
+
const trimmed = text?.trim() ?? ''
|
|
86
|
+
let data
|
|
87
|
+
try {
|
|
88
|
+
data = trimmed === '' ? null : JSON.parse(trimmed)
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.log(`[@ossy/app][proxy][error]`, e)
|
|
91
|
+
res.removeHeader('content-length')
|
|
92
|
+
const st = response.status
|
|
93
|
+
if (st === 401 || st === 403 || st === 404) {
|
|
94
|
+
res.status(st)
|
|
95
|
+
res.json(null)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
res.status(502)
|
|
99
|
+
res.json({ message: 'Upstream returned invalid JSON' })
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
res.removeHeader('content-length')
|
|
103
|
+
res.status(response.status)
|
|
104
|
+
res.json(data)
|
|
105
|
+
})
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
res.clearCookie('auth')
|
package/cli/server.js
CHANGED
|
@@ -84,8 +84,11 @@ const middleware = [
|
|
|
84
84
|
const userSettings = JSON.parse(req.signedCookies?.['x-ossy-user-settings'] || '{}')
|
|
85
85
|
req.userAppSettings = userSettings
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
// Incoming headers live on lowercase keys (`workspaceid`). Do not use
|
|
88
|
+
// `req.headers.workspaceId` — it misses the client header and duplicates
|
|
89
|
+
// the id (Node then surfaces `id, id` from req.get('workspaceId')).
|
|
90
|
+
if (userSettings.workspaceId && !req.get('workspaceId')) {
|
|
91
|
+
req.headers['workspaceid'] = userSettings.workspaceId
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
// Check for auth cookie
|
|
@@ -123,6 +126,8 @@ app.all('*all', (req, res) => {
|
|
|
123
126
|
isAuthenticated: req.isAuthenticated || false,
|
|
124
127
|
workspaceId: userAppSettings.workspaceId || buildTimeConfig.workspaceId,
|
|
125
128
|
apiUrl: buildTimeConfig.apiUrl,
|
|
129
|
+
/** Primary app shell sidebar: icon rail when true (persisted in `x-ossy-user-settings`). */
|
|
130
|
+
sidebarPrimaryCollapsed: userAppSettings.sidebarPrimaryCollapsed === true,
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
renderToString(App, appConfig)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"README.md",
|
|
67
67
|
"tsconfig.json"
|
|
68
68
|
],
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "b64b14021bc1f3aa6d8668a64754e0ba8b4ab63d"
|
|
70
70
|
}
|