@ossy/app 0.5.0 → 0.5.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/build.js +2 -2
- package/cli/proxy-internal.js +47 -0
- package/cli/server.js +2 -0
- package/package.json +11 -4
package/cli/build.js
CHANGED
|
@@ -33,7 +33,7 @@ export const build = async (cliArgs) => {
|
|
|
33
33
|
|
|
34
34
|
const appSourcePath = path.resolve(options['--source'] || 'src/App.jsx');
|
|
35
35
|
let apiSourcePath = path.resolve(options['--api-source'] || 'src/Api.js');
|
|
36
|
-
let middlewareSourcePath = path.resolve(options['--middleware-source'] || 'src/
|
|
36
|
+
let middlewareSourcePath = path.resolve(options['--middleware-source'] || 'src/middleware.js');
|
|
37
37
|
const configPath = path.resolve(options['--config'] || 'src/config.js');
|
|
38
38
|
const buildPath = path.resolve(options['--destination'] || 'build');
|
|
39
39
|
const publicDir = path.resolve('public')
|
|
@@ -53,7 +53,7 @@ export const build = async (cliArgs) => {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (!fs.existsSync(middlewareSourcePath)) {
|
|
56
|
-
middlewareSourcePath = path.resolve(scriptDir, '
|
|
56
|
+
middlewareSourcePath = path.resolve(scriptDir, 'middleware.js')
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (fs.existsSync(configPath)) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function ProxyInternal() {
|
|
2
|
+
return (req, res, next) => {
|
|
3
|
+
|
|
4
|
+
if (!req.originalUrl.startsWith('/@ossy')) {
|
|
5
|
+
return next()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const domain = process.env.OSSY_API_URL || 'https://api.ossy.se'
|
|
9
|
+
const url = `${domain}${req.path}`
|
|
10
|
+
const headers = JSON.parse(JSON.stringify(req.headers)) // Clone headers
|
|
11
|
+
const workspaceId = headers.workspaceId || config.workspaceId
|
|
12
|
+
|
|
13
|
+
if (workspaceId) {
|
|
14
|
+
headers['workspaceid'] = workspaceId
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const request = {
|
|
18
|
+
method: req.method,
|
|
19
|
+
headers: JSON.parse(JSON.stringify(req.headers))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!['GET', 'HEAD'].includes(req.method)) {
|
|
23
|
+
request.body = JSON.stringify(req.body)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fetch(url, request)
|
|
27
|
+
.then((response) => {
|
|
28
|
+
|
|
29
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
30
|
+
return response.json()
|
|
31
|
+
.then(data => {
|
|
32
|
+
res.status(response.status)
|
|
33
|
+
res.json(data)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
res.status(response.status)
|
|
38
|
+
res.json("")
|
|
39
|
+
})
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
const status = error.status
|
|
42
|
+
res.status(status || 500)
|
|
43
|
+
res.json({ message: error.message || 'Internal Server Error' })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
}
|
package/cli/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import express from 'express'
|
|
|
5
5
|
import morgan from 'morgan'
|
|
6
6
|
import { Router } from '@ossy/router'
|
|
7
7
|
import { prerenderToNodeStream } from 'react-dom/static'
|
|
8
|
+
import { ProxyInternal } from './proxy-internal.js'
|
|
8
9
|
|
|
9
10
|
import App from '%%@ossy/app/source-file%%'
|
|
10
11
|
import ApiRoutes from '%%@ossy/api/source-file%%'
|
|
@@ -24,6 +25,7 @@ const middleware = [
|
|
|
24
25
|
morgan('tiny'),
|
|
25
26
|
express.static(ROOT_PATH),
|
|
26
27
|
express.json({ strict: false }),
|
|
28
|
+
ProxyInternal(),
|
|
27
29
|
...(Middleware || [])
|
|
28
30
|
]
|
|
29
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -20,8 +20,15 @@
|
|
|
20
20
|
"@babel/preset-env": "^7.26.0",
|
|
21
21
|
"@babel/preset-react": "^7.26.3",
|
|
22
22
|
"@babel/register": "^7.25.9",
|
|
23
|
-
"@ossy/
|
|
24
|
-
"@ossy/
|
|
23
|
+
"@ossy/connected-components": ">=0.5.0 <1.0.0",
|
|
24
|
+
"@ossy/design-system": ">=0.5.0 <1.0.0",
|
|
25
|
+
"@ossy/design-system-extras": ">=0.5.0 <1.0.0",
|
|
26
|
+
"@ossy/resource-templates": ">=0.5.0 <1.0.0",
|
|
27
|
+
"@ossy/router": ">=0.5.0 <1.0.0",
|
|
28
|
+
"@ossy/router-react": ">=0.5.0 <1.0.0",
|
|
29
|
+
"@ossy/sdk": ">=0.5.0 <1.0.0",
|
|
30
|
+
"@ossy/sdk-react": ">=0.5.0 <1.0.0",
|
|
31
|
+
"@ossy/themes": ">=0.5.0 <1.0.0",
|
|
25
32
|
"@rollup/plugin-alias": "^5.1.1",
|
|
26
33
|
"@rollup/plugin-babel": "6.0.4",
|
|
27
34
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -50,5 +57,5 @@
|
|
|
50
57
|
"/cli",
|
|
51
58
|
"README.md"
|
|
52
59
|
],
|
|
53
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "71269efebe05376c2ead8a2a81a94ddf098996c6"
|
|
54
61
|
}
|