@ossy/app 0.1.9 → 0.3.0

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.
@@ -0,0 +1,3 @@
1
+ // dummy file so it can be imported
2
+
3
+ export default undefined
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
@@ -1,27 +1,42 @@
1
1
  import path from 'path';
2
2
  import url from 'url'
3
3
  import React, { createElement } from 'react';
4
- import express from 'express';
4
+ import express from 'express'
5
+ import morgan from 'morgan'
6
+ import { Router } from '@ossy/router'
5
7
  import { prerenderToNodeStream } from 'react-dom/static'
8
+
6
9
  import App from '%%@ossy/app/source-file%%'
7
- import ApiRouter from '%%@ossy/api/source-file%%'
10
+ import ApiRoutes from '%%@ossy/api/source-file%%'
11
+ import Middleware from '%%@ossy/middleware/source-file%%'
8
12
 
9
13
  const app = express();
10
14
 
11
15
  const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
12
16
  const ROOT_PATH = path.resolve(currentDir, 'public')
13
17
 
14
- app.use(express.static(ROOT_PATH));
18
+ const middleware = [
19
+ morgan('tiny'),
20
+ express.static(ROOT_PATH),
21
+ ...(Middleware || [])
22
+ ]
23
+
24
+ app.use(middleware)
25
+
26
+ const ApiRouter = Router.of({ pages: ApiRoutes || [] })
15
27
 
16
- ApiRouter && app.use('/*api', ApiRouter)
28
+ app.all('/*all', (req, res) => {
29
+ const pathname = req.originalUrl
17
30
 
18
- app.get('/*app', (req, res) => {
31
+ const apiRoute = ApiRouter.getPageByUrl(pathname)
19
32
 
20
- console.log('[@ossy/cli][app][server] req.url: ', req.url)
33
+ if (apiRoute) {
34
+ apiRoute.handle(req, res)
35
+ }
21
36
 
22
- renderToString(App, { url: req.url })
23
- .then(html => { res.send(html) })
24
- .catch(err => { res.send(err) })
37
+ renderToString(App, { url: req.url })
38
+ .then(html => { res.send(html) })
39
+ .catch(err => { res.send(err) })
25
40
 
26
41
  });
27
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "0.1.9",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
@@ -20,6 +20,8 @@
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/router": ">=0.1.9 <1.0.0",
24
+ "@ossy/router-react": ">=0.1.9 <1.0.0",
23
25
  "@rollup/plugin-alias": "^5.1.1",
24
26
  "@rollup/plugin-babel": "6.0.4",
25
27
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -32,6 +34,7 @@
32
34
  "arg": "^5.0.2",
33
35
  "babel-loader": "^9.2.1",
34
36
  "express": ">=5.0.0 <6.0.0",
37
+ "morgan": ">=1.10.1 <2.0.0",
35
38
  "react": ">=19.0.0 <20.0.0",
36
39
  "react-dom": ">=19.0.0 <20.0.0",
37
40
  "rollup": "^4.24.3",
@@ -47,5 +50,5 @@
47
50
  "/cli",
48
51
  "README.md"
49
52
  ],
50
- "gitHead": "b12e155a1e0e5b57f60d786d548d5bf761dbefe6"
53
+ "gitHead": "0d51b85b7a041971810f0c224cf79d655c7f933c"
51
54
  }