@ossy/app 0.6.0 → 0.6.2

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.
@@ -4,6 +4,45 @@ export function ProxyInternal() {
4
4
  if (!req.originalUrl.startsWith('/@ossy')) {
5
5
  return next()
6
6
  }
7
+
8
+ if (req.originalUrl.startsWith('/@ossy/users/me/app-settings') && req.method === 'PATCH') {
9
+
10
+ if (!req.body) {
11
+ res.status(400)
12
+ res.json("Invalid request body")
13
+ return
14
+ }
15
+
16
+ const requestedSettings = req.body
17
+
18
+
19
+ const expiresMaxAge = 2147483647 // Max age for cookies in milliseconds
20
+
21
+ const userSettings = JSON.parse(req.signedCookies?.['x-ossy-user-settings'] || '{}')
22
+
23
+ const updatedSettings = {
24
+ ...userSettings,
25
+ ...requestedSettings
26
+ }
27
+
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
+
34
+ res.status(201)
35
+ res.json("")
36
+ return
37
+ }
38
+
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
+ }
7
46
 
8
47
  console.log(`[@ossy/app][proxy] ${req.method} ${req.originalUrl}`)
9
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,29 +24,7 @@ if (Middleware !== undefined) {
24
24
  const middleware = [
25
25
  morgan('tiny'),
26
26
  express.json({ strict: false }),
27
- (req, res, next) => {
28
- const domain = process.env.OSSY_API_URL || 'https://api.ossy.se'
29
- const url = `${domain}/api/v0/users/me`
30
- const headers = { ...(req.headers || {}) } // Clone headers
31
-
32
- const request = {
33
- method: req.method,
34
- headers: JSON.parse(JSON.stringify(req.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
-
49
- },
27
+ cookieParser(process.env.OSSY_COOKIE_SECRET || 'default_secret'),
50
28
  ...(Middleware || []),
51
29
  express.static(ROOT_PATH),
52
30
  ProxyInternal(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
@@ -40,6 +40,7 @@
40
40
  "@rollup/plugin-typescript": "^12.3.0",
41
41
  "arg": "^5.0.2",
42
42
  "babel-loader": "^9.2.1",
43
+ "cookie-parser": "^1.4.7",
43
44
  "express": ">=5.0.0 <6.0.0",
44
45
  "morgan": ">=1.10.1 <2.0.0",
45
46
  "react": ">=19.0.0 <20.0.0",
@@ -57,5 +58,5 @@
57
58
  "/cli",
58
59
  "README.md"
59
60
  ],
60
- "gitHead": "eafa7411add27f733b8764e95cb05654b0e38e74"
61
+ "gitHead": "f95185763b99291b1254f57bc4eb1ee2b7b5e191"
61
62
  }