@ossy/app 0.6.1 → 0.6.3
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 +29 -29
- package/cli/server.js +5 -22
- package/package.json +2 -2
package/cli/proxy-internal.js
CHANGED
|
@@ -5,44 +5,44 @@ export function ProxyInternal() {
|
|
|
5
5
|
return next()
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
if (req.originalUrl.startsWith('/@ossy/users/me/app-settings') && req.method === 'PATCH') {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (!req.body) {
|
|
11
|
+
res.status(400)
|
|
12
|
+
res.json("Invalid request body")
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const requestedSettings = req.body
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const expiresMaxAge = 2147483647 // Max age for cookies in milliseconds
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const userSettings = JSON.parse(req.signedCookies?.['x-ossy-user-settings'] || '{}')
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const updatedSettings = {
|
|
24
|
+
...userSettings,
|
|
25
|
+
...requestedSettings
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
res.cookie('x-ossy-user-settings', JSON.stringify(updatedSettings), {
|
|
29
|
+
httpOnly: true,
|
|
30
|
+
signed: true,
|
|
31
|
+
expires: new Date(Date.now() + expiresMaxAge)
|
|
32
|
+
})
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
res.status(201)
|
|
35
|
+
res.json("")
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
if (req.originalUrl.startsWith('/@ossy/users/me/app-settings') && req.method === 'GET') {
|
|
40
|
+
LogService.Info({ message: `[UsersService][HandleUserAppSettings] METHOD ${req.method}` })
|
|
41
|
+
const userSettings = JSON.parse(req.signedCookies?.['x-ossy-user-settings'] || '{}')
|
|
42
|
+
res.status(200)
|
|
43
|
+
res.json(userSettings)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
console.log(`[@ossy/app][proxy] ${req.method} ${req.originalUrl}`)
|
|
48
48
|
|
package/cli/server.js
CHANGED
|
@@ -6,6 +6,7 @@ import morgan from 'morgan'
|
|
|
6
6
|
import { Router } from '@ossy/router'
|
|
7
7
|
import { prerenderToNodeStream } from 'react-dom/static'
|
|
8
8
|
import { ProxyInternal } from './proxy-internal.js'
|
|
9
|
+
import cookieParser from 'cookie-parser'
|
|
9
10
|
|
|
10
11
|
import App from '%%@ossy/app/source-file%%'
|
|
11
12
|
import ApiRoutes from '%%@ossy/api/source-file%%'
|
|
@@ -16,7 +17,6 @@ const app = express();
|
|
|
16
17
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
|
|
17
18
|
const ROOT_PATH = path.resolve(currentDir, 'public')
|
|
18
19
|
|
|
19
|
-
|
|
20
20
|
if (Middleware !== undefined) {
|
|
21
21
|
console.log(`[@ossy/app][server] ${Middleware?.length || 0} custom middleware loaded`)
|
|
22
22
|
}
|
|
@@ -24,28 +24,11 @@ if (Middleware !== undefined) {
|
|
|
24
24
|
const middleware = [
|
|
25
25
|
morgan('tiny'),
|
|
26
26
|
express.json({ strict: false }),
|
|
27
|
+
cookieParser(process.env.OSSY_COOKIE_SECRET || 'default_secret'),
|
|
27
28
|
(req, res, next) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const request = {
|
|
33
|
-
method: req.method,
|
|
34
|
-
headers: JSON.parse(JSON.stringify(headers))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fetch(url, request)
|
|
38
|
-
.then(response => response.json())
|
|
39
|
-
.then((userAppSettings) => {
|
|
40
|
-
req.userAppSettings = userAppSettings || {}
|
|
41
|
-
next()
|
|
42
|
-
})
|
|
43
|
-
.catch((error) => {
|
|
44
|
-
console.log(`[@ossy/app][server][error]`, error)
|
|
45
|
-
req.userAppSettings = {}
|
|
46
|
-
next()
|
|
47
|
-
})
|
|
48
|
-
|
|
29
|
+
const userSettings = JSON.parse(req.signedCookies?.['x-ossy-user-settings'] || '{}')
|
|
30
|
+
req.userAppSettings = userSettings
|
|
31
|
+
next()
|
|
49
32
|
},
|
|
50
33
|
...(Middleware || []),
|
|
51
34
|
express.static(ROOT_PATH),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"/cli",
|
|
59
59
|
"README.md"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "dd003532612a1f93c33f3649985e3516d0b765b0"
|
|
62
62
|
}
|