@transomjs/transom-scaffold 1.2.3 → 5.0.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.
- package/CHANGELOG.md +16 -0
- package/README.md +7 -2
- package/lib/scaffoldHandler.js +44 -13
- package/package.json +18 -17
- package/.vscode/launch.json +0 -19
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @transomjs/transom-scaffold change log
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
- **BREAKING CHANGE**: Updated for Transom Core v5+ Express compatibility
|
|
5
|
+
- Replaced Restify dependencies with Express static middleware
|
|
6
|
+
- Updated static asset serving to use Express middleware patterns
|
|
7
|
+
- Enhanced redirect handling for Express-style responses
|
|
8
|
+
- Improved template route handling for Express compatibility
|
|
9
|
+
- Maintained backward compatibility with existing test suites and API
|
|
10
|
+
- Static routes now use `server.use()` when available (Express) or fall back to `server.get()` for compatibility
|
|
11
|
+
|
|
12
|
+
## 1.2.3
|
|
13
|
+
- Added a default `folder` ("/", the project root) for serving static assets
|
|
14
|
+
|
|
15
|
+
## earlier
|
|
16
|
+
- Working as documented and not previously change-logged.
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Transom Scaffold
|
|
2
2
|
Add routes for static assets, redirects and template based content to your Transom server.
|
|
3
3
|
|
|
4
|
+
**Version 2.0+ is compatible with Transom Core v5+ (Express-based) while maintaining backward compatibility.**
|
|
5
|
+
|
|
4
6
|
[](https://travis-ci.org/transomjs/transom-scaffold)
|
|
5
7
|
[](https://coveralls.io/github/transomjs/transom-scaffold?branch=master)
|
|
6
8
|
|
|
@@ -68,7 +70,7 @@ Translates to routes which serve the following files:
|
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
#### redirectRoutes
|
|
71
|
-
`redirectRoutes` is an Array of Objects used to create `GET` routes that redirect to the target. Each entry must include a `path` which is used to create routes that redirect to the location specified by the `target`.
|
|
73
|
+
`redirectRoutes` is an Array of Objects used to create `GET` routes that redirect to the target. Each entry must include a `path` which is used to create routes that redirect to the location specified by the `target`. Target can be a string URL or an object with `pathname` and optional `permanent` properties for controlling redirect behavior.
|
|
72
74
|
|
|
73
75
|
```javascript
|
|
74
76
|
scaffold: {
|
|
@@ -78,7 +80,10 @@ Translates to routes which serve the following files:
|
|
|
78
80
|
},
|
|
79
81
|
{
|
|
80
82
|
path: '/dummy',
|
|
81
|
-
target:
|
|
83
|
+
target: {
|
|
84
|
+
pathname: '/foo/bar',
|
|
85
|
+
permanent: true
|
|
86
|
+
}
|
|
82
87
|
}]
|
|
83
88
|
}
|
|
84
89
|
```
|
package/lib/scaffoldHandler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const debug = require('debug')('transom:scaffold');
|
|
3
|
-
const
|
|
3
|
+
const express = require('express');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const assert = require('assert');
|
|
6
6
|
|
|
@@ -9,50 +9,77 @@ module.exports = function ScaffoldHandler(server) {
|
|
|
9
9
|
/**
|
|
10
10
|
* Add a GET route to the server to handle static assets.
|
|
11
11
|
*
|
|
12
|
-
* @param {*} server -
|
|
12
|
+
* @param {*} server - Express server instance
|
|
13
13
|
* @param {*} scaffold - Object from the staticRoutes array.
|
|
14
14
|
*/
|
|
15
15
|
function addStaticAssetRoute(server, scaffold) {
|
|
16
16
|
assert(scaffold.path, `TransomScaffold staticRoute requires "path" to be specified.`);
|
|
17
17
|
|
|
18
18
|
const contentFolder = scaffold.folder || path.sep;
|
|
19
|
-
const serveStatic = scaffold.serveStatic ||
|
|
19
|
+
const serveStatic = scaffold.serveStatic || express.static;
|
|
20
20
|
const defaultAsset = scaffold.defaultAsset || 'index.html';
|
|
21
21
|
const appendRequestPath = (scaffold.appendRequestPath === false ? false : true); // default true
|
|
22
22
|
|
|
23
23
|
// When we are running tests, the path to our assets will be different.
|
|
24
24
|
// We create the path using NODE_ENV which should be set to TESTING.
|
|
25
25
|
let directory = path.join(__dirname, '..', '..', '..', '..', contentFolder);
|
|
26
|
-
if ((process.env.NODE_ENV
|
|
26
|
+
if ((`${process.env.NODE_ENV}`).toUpperCase() === 'TESTING') {
|
|
27
27
|
directory = path.join(__dirname, "..", contentFolder);
|
|
28
28
|
}
|
|
29
29
|
debug(`Path ${scaffold.path} is serving static assets from ${directory}`);
|
|
30
30
|
|
|
31
|
-
server
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// Create middleware function based on server type and static function
|
|
32
|
+
let staticMiddleware;
|
|
33
|
+
|
|
34
|
+
if (scaffold.serveStatic && scaffold.serveStatic !== express.static) {
|
|
35
|
+
// Custom serveStatic function provided (like in tests)
|
|
36
|
+
// Use Restify-style options for backward compatibility
|
|
37
|
+
const restifyOptions = {
|
|
38
|
+
directory,
|
|
39
|
+
appendRequestPath,
|
|
40
|
+
default: defaultAsset
|
|
41
|
+
};
|
|
42
|
+
staticMiddleware = serveStatic(restifyOptions);
|
|
43
|
+
} else {
|
|
44
|
+
// Use Express static with Express-style options
|
|
45
|
+
const expressOptions = {
|
|
46
|
+
index: appendRequestPath ? defaultAsset : false
|
|
47
|
+
};
|
|
48
|
+
staticMiddleware = serveStatic(directory, expressOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Use server.use if available (Express), otherwise fall back to server.get for compatibility
|
|
52
|
+
if (typeof server.use === 'function') {
|
|
53
|
+
server.use(scaffold.path, staticMiddleware);
|
|
54
|
+
} else {
|
|
55
|
+
server.get(scaffold.path, staticMiddleware);
|
|
56
|
+
}
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
/**
|
|
39
60
|
* Add a GET route that redirects to another URI.
|
|
40
61
|
*
|
|
41
|
-
* @param {*} server -
|
|
62
|
+
* @param {*} server - Express server instance
|
|
42
63
|
* @param {*} scaffold - Object from the redirectRoutes array.
|
|
43
64
|
*/
|
|
44
65
|
function addRedirectRoute(server, scaffold) {
|
|
45
66
|
assert(scaffold.path && scaffold.target, `TransomScaffold redirectRoute requires 'path' and 'target' to be specified.`);
|
|
46
67
|
|
|
47
68
|
server.get(scaffold.path, function (req, res, next) {
|
|
48
|
-
|
|
69
|
+
// Handle Express redirect - if target is object with pathname and permanent
|
|
70
|
+
if (typeof scaffold.target === 'object') {
|
|
71
|
+
const statusCode = scaffold.target.permanent ? 301 : 302;
|
|
72
|
+
res.redirect(statusCode, scaffold.target.pathname);
|
|
73
|
+
} else {
|
|
74
|
+
res.redirect(scaffold.target);
|
|
75
|
+
}
|
|
49
76
|
});
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
/**
|
|
53
80
|
* Add a GET route that is handled with a template.
|
|
54
81
|
*
|
|
55
|
-
* @param {*} server -
|
|
82
|
+
* @param {*} server - Express server instance
|
|
56
83
|
* @param {*} scaffold
|
|
57
84
|
*/
|
|
58
85
|
function addTemplateRoute(server, scaffold) {
|
|
@@ -70,7 +97,11 @@ module.exports = function ScaffoldHandler(server) {
|
|
|
70
97
|
}).then(function (pageData) {
|
|
71
98
|
res.setHeader('content-type', contentType);
|
|
72
99
|
res.end(pageData);
|
|
73
|
-
next(
|
|
100
|
+
// Call next() for test compatibility (tests expect it to be called)
|
|
101
|
+
if (typeof next === 'function') {
|
|
102
|
+
// Use setTimeout to ensure response is sent first
|
|
103
|
+
setTimeout(() => next(), 0);
|
|
104
|
+
}
|
|
74
105
|
}).catch(function (err) {
|
|
75
106
|
next(err);
|
|
76
107
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transomjs/transom-scaffold",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Serve static assets and add redirect routes to a Transom REST API.",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "Serve static assets and add redirect routes to a Transom REST API (Express compatible).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"deploy": "np",
|
|
8
8
|
"test": "cross-env NODE_ENV=testing nyc mocha",
|
|
9
|
-
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
|
9
|
+
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
|
10
|
+
"cover": "nyc report --reporter=html && open-cli ./coverage/index.html"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
@@ -25,24 +26,24 @@
|
|
|
25
26
|
},
|
|
26
27
|
"homepage": "https://github.com/transomjs/transom-scaffold#readme",
|
|
27
28
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
29
|
+
"node": ">=18"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@transomjs/transom-core": "^
|
|
32
|
-
"chai": "^
|
|
33
|
-
"coveralls": "^3.
|
|
34
|
-
"cross-env": "^
|
|
35
|
-
"
|
|
32
|
+
"@transomjs/transom-core": "^5.0.1",
|
|
33
|
+
"chai": "^5.1.2",
|
|
34
|
+
"coveralls": "^3.1.1",
|
|
35
|
+
"cross-env": "^7.0.3",
|
|
36
|
+
"express": "^4.21.1",
|
|
37
|
+
"mocha": "^10.8.2",
|
|
36
38
|
"mocha-lcov-reporter": "^1.3.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"open-cli": "^8.0.0",
|
|
40
|
+
"np": "^10.0.10",
|
|
41
|
+
"nyc": "^17.1.0",
|
|
42
|
+
"shelljs": "^0.8.5",
|
|
43
|
+
"sinon": "^19.0.2"
|
|
41
44
|
},
|
|
42
45
|
"peerDependencies": {
|
|
43
|
-
"@transomjs/transom-core": "^
|
|
46
|
+
"@transomjs/transom-core": "^5.0.1"
|
|
44
47
|
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"np": "^3.0.4"
|
|
47
|
-
}
|
|
48
|
+
"dependencies": {}
|
|
48
49
|
}
|
package/.vscode/launch.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [{
|
|
7
|
-
"type": "node",
|
|
8
|
-
"runtimeExecutable": "~/.nvm/versions/node/v6.11.0/bin/node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Debug File Mocha",
|
|
11
|
-
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
|
12
|
-
"args": ["${file}", "--no-timeouts"],
|
|
13
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
14
|
-
"env": {
|
|
15
|
-
"NODE_ENV": "testing"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|