@kne/fastify-live-components-site 0.1.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,33 @@
1
+ /**
2
+ * 公开接口 CORS:允许任意 Origin。
3
+ * 仅用于站点入口(/:shorten/*)与内容访问(/content/:code),不含站点管理 /site/*。
4
+ */
5
+ const setCorsHeaders = (request, reply) => {
6
+ reply.header('Access-Control-Allow-Origin', '*');
7
+ reply.header('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS');
8
+ reply.header('Access-Control-Allow-Headers', request.headers['access-control-request-headers'] || 'Content-Type, Authorization, X-Requested-With, x-user-code');
9
+ reply.header('Access-Control-Max-Age', '86400');
10
+ };
11
+
12
+ const allowCors = async (request, reply) => {
13
+ setCorsHeaders(request, reply);
14
+ };
15
+
16
+ const handleOptions = async (request, reply) => {
17
+ setCorsHeaders(request, reply);
18
+ return reply.code(204).send();
19
+ };
20
+
21
+ const normalizeHooks = hooks => {
22
+ if (!hooks) {
23
+ return [];
24
+ }
25
+ return Array.isArray(hooks) ? hooks : [hooks];
26
+ };
27
+
28
+ module.exports = {
29
+ setCorsHeaders,
30
+ allowCors,
31
+ handleOptions,
32
+ normalizeHooks
33
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@kne/fastify-live-components-site",
3
+ "version": "0.1.0",
4
+ "description": "Fastify 插件:为 LiveComponentEditor 提供远程站点文件树与短链访问管理",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "init": "husky",
8
+ "build:md": "npx @kne/md-doc",
9
+ "start:md": "npx @kne/md-doc --watch",
10
+ "prettier": "prettier --config .prettierrc --write '{libs/**/*,index}.{js,jsx,ts,tsx,json,css,scss}'",
11
+ "lint-staged": "npx lint-staged",
12
+ "test": "mocha --exit test/**/*.test.js",
13
+ "test:coverage": "nyc --reporter=html --reporter=text mocha test/**/*.test.js --timeout 10000"
14
+ },
15
+ "lint-staged": {
16
+ "{libs/**/*,index}.{js,jsx,ts,tsx,json,css,scss}": [
17
+ "prettier --config .prettierrc --write",
18
+ "git add"
19
+ ]
20
+ },
21
+ "files": [
22
+ "index.js",
23
+ "libs"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/kne-union/fastify-live-components-site.git"
28
+ },
29
+ "keywords": [
30
+ "fastify",
31
+ "live-components",
32
+ "file-tree",
33
+ "shorten",
34
+ "fastify-plugin"
35
+ ],
36
+ "author": "linzp",
37
+ "license": "ISC",
38
+ "bugs": {
39
+ "url": "https://github.com/kne-union/fastify-live-components-site/issues"
40
+ },
41
+ "homepage": "https://github.com/kne-union/fastify-live-components-site#readme",
42
+ "dependencies": {
43
+ "http-errors": "^2.0.0",
44
+ "lodash": "^4.17.21"
45
+ },
46
+ "peerDependencies": {
47
+ "@kne/fastify-account": "*",
48
+ "@kne/fastify-namespace": "*",
49
+ "@kne/fastify-sequelize": "*",
50
+ "@kne/fastify-shorten": "*",
51
+ "fastify-plugin": ">=5"
52
+ },
53
+ "devDependencies": {
54
+ "@fastify/env": "^5.0.2",
55
+ "@fastify/sensible": "^6.0.4",
56
+ "@kne/fastify-namespace": "^1.2.1",
57
+ "@kne/fastify-sequelize": "^3.0.6",
58
+ "@kne/fastify-shorten": "^1.0.16",
59
+ "chai": "^6.2.2",
60
+ "fastify": "^5.4.0",
61
+ "fastify-plugin": "^5.0.1",
62
+ "husky": "^9.0.11",
63
+ "mocha": "^11.7.5",
64
+ "nodemon": "^3.1.3",
65
+ "nyc": "^17.1.0",
66
+ "prettier": "^3.2.5",
67
+ "qs": "^6.14.0",
68
+ "sqlite3": "^5.1.7"
69
+ }
70
+ }