@ossy/app 0.1.9 → 0.2.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.
Files changed (2) hide show
  1. package/cli/server.js +17 -8
  2. package/package.json +5 -2
package/cli/server.js CHANGED
@@ -1,27 +1,36 @@
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%%'
8
11
 
9
12
  const app = express();
10
13
 
11
14
  const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
12
15
  const ROOT_PATH = path.resolve(currentDir, 'public')
13
16
 
17
+ app.use(morgan('tiny'));
14
18
  app.use(express.static(ROOT_PATH));
15
19
 
16
- ApiRouter && app.use('/*api', ApiRouter)
20
+ const ApiRouter = Router.of({ pages: ApiRoutes || [] })
21
+
22
+ app.all('/*all', (req, res) => {
23
+ const pathname = req.originalUrl
17
24
 
18
- app.get('/*app', (req, res) => {
25
+ const apiRoute = ApiRouter.getPageByUrl(pathname)
19
26
 
20
- console.log('[@ossy/cli][app][server] req.url: ', req.url)
27
+ if (apiRoute) {
28
+ apiRoute.handle(req, res)
29
+ }
21
30
 
22
- renderToString(App, { url: req.url })
23
- .then(html => { res.send(html) })
24
- .catch(err => { res.send(err) })
31
+ renderToString(App, { url: req.url })
32
+ .then(html => { res.send(html) })
33
+ .catch(err => { res.send(err) })
25
34
 
26
35
  });
27
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "0.1.9",
3
+ "version": "0.2.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": "b63b938de06e69485066296ca287d71dc9558461"
51
54
  }