@ossy/app 0.2.0 → 0.3.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/Middleware.js +3 -0
- package/cli/build.js +13 -0
- package/cli/server.js +14 -2
- package/package.json +2 -2
package/cli/build.js
CHANGED
|
@@ -33,6 +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/Middleware.js');
|
|
36
37
|
const configPath = path.resolve(options['--config'] || 'src/config.js');
|
|
37
38
|
const buildPath = path.resolve(options['--destination'] || 'build');
|
|
38
39
|
const publicDir = path.resolve('public')
|
|
@@ -51,6 +52,10 @@ export const build = async (cliArgs) => {
|
|
|
51
52
|
apiSourcePath = path.resolve(scriptDir, 'Api.js')
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
if (!fs.existsSync(middlewareSourcePath)) {
|
|
56
|
+
apiSourcePath = path.resolve(scriptDir, 'Middleware.js')
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
if (fs.existsSync(configPath)) {
|
|
55
60
|
inputFiles.push(configPath)
|
|
56
61
|
}
|
|
@@ -61,14 +66,22 @@ export const build = async (cliArgs) => {
|
|
|
61
66
|
remove({ targets: buildPath }),
|
|
62
67
|
// inject({ 'React': 'react' }),
|
|
63
68
|
replace({
|
|
69
|
+
preventAssignment: true,
|
|
64
70
|
delimiters: ['%%', '%%'],
|
|
65
71
|
'@ossy/app/source-file': appSourcePath,
|
|
66
72
|
}),
|
|
67
73
|
replace({
|
|
74
|
+
preventAssignment: true,
|
|
68
75
|
delimiters: ['%%', '%%'],
|
|
69
76
|
'@ossy/api/source-file': apiSourcePath,
|
|
70
77
|
}),
|
|
71
78
|
replace({
|
|
79
|
+
preventAssignment: true,
|
|
80
|
+
delimiters: ['%%', '%%'],
|
|
81
|
+
'@ossy/middleware/source-file': apiSourcePath,
|
|
82
|
+
}),
|
|
83
|
+
replace({
|
|
84
|
+
preventAssignment: true,
|
|
72
85
|
'process.env.NODE_ENV': JSON.stringify('production')
|
|
73
86
|
}),
|
|
74
87
|
json(),
|
package/cli/server.js
CHANGED
|
@@ -8,14 +8,25 @@ import { prerenderToNodeStream } from 'react-dom/static'
|
|
|
8
8
|
|
|
9
9
|
import App from '%%@ossy/app/source-file%%'
|
|
10
10
|
import ApiRoutes from '%%@ossy/api/source-file%%'
|
|
11
|
+
import Middleware from '%%@ossy/middleware/source-file%%'
|
|
11
12
|
|
|
12
13
|
const app = express();
|
|
13
14
|
|
|
14
15
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
|
|
15
16
|
const ROOT_PATH = path.resolve(currentDir, 'public')
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
if (Middleware !== undefined) {
|
|
20
|
+
console.log(`[@ossy/cli][app][server] ${Middleware?.length || 0} custom middleware loaded`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const middleware = [
|
|
24
|
+
morgan('tiny'),
|
|
25
|
+
express.static(ROOT_PATH),
|
|
26
|
+
...(Middleware || [])
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
app.use(middleware)
|
|
19
30
|
|
|
20
31
|
const ApiRouter = Router.of({ pages: ApiRoutes || [] })
|
|
21
32
|
|
|
@@ -25,6 +36,7 @@ app.all('/*all', (req, res) => {
|
|
|
25
36
|
const apiRoute = ApiRouter.getPageByUrl(pathname)
|
|
26
37
|
|
|
27
38
|
if (apiRoute) {
|
|
39
|
+
console.log(`[@ossy/cli][app][server] Handling API route: ${pathname}`)
|
|
28
40
|
apiRoute.handle(req, res)
|
|
29
41
|
}
|
|
30
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"/cli",
|
|
51
51
|
"README.md"
|
|
52
52
|
],
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "b97ec6944720f804a43ae63bde88c3e14b0521cf"
|
|
54
54
|
}
|