create-prisma-php-app 4.3.6 → 4.3.8
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/dist/settings/bs-config.ts +123 -16
- package/dist/src/Lib/Auth/Auth.php +10 -5
- package/package.json +1 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createProxyMiddleware,
|
|
3
|
+
responseInterceptor,
|
|
4
|
+
} from "http-proxy-middleware";
|
|
2
5
|
import { writeFileSync, existsSync, mkdirSync } from "fs";
|
|
3
6
|
import browserSync, { BrowserSyncInstance } from "browser-sync";
|
|
4
7
|
import prismaPhpConfigJson from "../prisma-php.json";
|
|
@@ -13,11 +16,12 @@ import {
|
|
|
13
16
|
} from "./class-imports";
|
|
14
17
|
import { checkComponentImports } from "./component-import-checker";
|
|
15
18
|
import { DebouncedWorker, createSrcWatcher, DEFAULT_AWF } from "./utils.js";
|
|
19
|
+
import chalk from "chalk";
|
|
16
20
|
|
|
17
21
|
const { __dirname } = getFileMeta();
|
|
18
22
|
const bs: BrowserSyncInstance = browserSync.create();
|
|
19
23
|
|
|
20
|
-
const PUBLIC_IGNORE_DIRS = [
|
|
24
|
+
const PUBLIC_IGNORE_DIRS = [""];
|
|
21
25
|
|
|
22
26
|
const pipeline = new DebouncedWorker(
|
|
23
27
|
async () => {
|
|
@@ -46,18 +50,18 @@ const pipeline = new DebouncedWorker(
|
|
|
46
50
|
}
|
|
47
51
|
},
|
|
48
52
|
350,
|
|
49
|
-
"bs-pipeline"
|
|
53
|
+
"bs-pipeline",
|
|
50
54
|
);
|
|
51
55
|
|
|
52
56
|
const publicPipeline = new DebouncedWorker(
|
|
53
57
|
async () => {
|
|
54
|
-
console.log("→ Public directory changed, reloading browser...");
|
|
58
|
+
console.log(chalk.cyan("→ Public directory changed, reloading browser..."));
|
|
55
59
|
if (bs.active) {
|
|
56
60
|
bs.reload();
|
|
57
61
|
}
|
|
58
62
|
},
|
|
59
63
|
350,
|
|
60
|
-
"bs-public-pipeline"
|
|
64
|
+
"bs-public-pipeline",
|
|
61
65
|
);
|
|
62
66
|
|
|
63
67
|
createSrcWatcher(join(SRC_DIR, "**", "*"), {
|
|
@@ -90,16 +94,17 @@ createSrcWatcher(join(PUBLIC_DIR, "**", "*"), {
|
|
|
90
94
|
|
|
91
95
|
const viteFlagFile = join(__dirname, "..", ".pp", ".vite-build-complete");
|
|
92
96
|
mkdirSync(dirname(viteFlagFile), { recursive: true });
|
|
93
|
-
writeFileSync(viteFlagFile, "");
|
|
94
97
|
|
|
95
98
|
if (!existsSync(viteFlagFile)) {
|
|
96
99
|
writeFileSync(viteFlagFile, "0");
|
|
100
|
+
} else {
|
|
101
|
+
writeFileSync(viteFlagFile, "");
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
createSrcWatcher(viteFlagFile, {
|
|
100
105
|
onEvent: (ev) => {
|
|
101
106
|
if (ev === "change" && bs.active) {
|
|
102
|
-
console.log("→ Vite build complete, reloading browser...");
|
|
107
|
+
console.log(chalk.green("→ Vite build complete, reloading browser..."));
|
|
103
108
|
bs.reload();
|
|
104
109
|
}
|
|
105
110
|
},
|
|
@@ -119,36 +124,138 @@ bs.init(
|
|
|
119
124
|
res.setHeader("Expires", "0");
|
|
120
125
|
next();
|
|
121
126
|
},
|
|
127
|
+
|
|
128
|
+
(req, _, next) => {
|
|
129
|
+
const time = new Date().toLocaleTimeString();
|
|
130
|
+
console.log(
|
|
131
|
+
`${chalk.gray(time)} ${chalk.cyan("[Proxy]")} ${chalk.bold(req.method)} ${req.url}`,
|
|
132
|
+
);
|
|
133
|
+
next();
|
|
134
|
+
},
|
|
135
|
+
|
|
122
136
|
createProxyMiddleware({
|
|
123
137
|
target: prismaPhpConfigJson.bsTarget,
|
|
124
138
|
changeOrigin: true,
|
|
125
139
|
pathRewrite: {},
|
|
140
|
+
selfHandleResponse: true,
|
|
141
|
+
|
|
142
|
+
on: {
|
|
143
|
+
proxyReq: (proxyReq, req, _res) => {
|
|
144
|
+
proxyReq.setHeader("Accept-Encoding", "");
|
|
145
|
+
|
|
146
|
+
const sendsJson =
|
|
147
|
+
req.headers["content-type"]?.includes("application/json");
|
|
148
|
+
const asksJson =
|
|
149
|
+
req.headers["accept"]?.includes("application/json");
|
|
150
|
+
|
|
151
|
+
if (!sendsJson && !asksJson) return;
|
|
152
|
+
|
|
153
|
+
const originalWrite = proxyReq.write;
|
|
154
|
+
proxyReq.write = function (data, ...args) {
|
|
155
|
+
if (data) {
|
|
156
|
+
try {
|
|
157
|
+
const body = data.toString();
|
|
158
|
+
const json = JSON.parse(body);
|
|
159
|
+
console.log(
|
|
160
|
+
chalk.blue("→ API Request:"),
|
|
161
|
+
JSON.stringify(json, null, 2),
|
|
162
|
+
);
|
|
163
|
+
} catch {
|
|
164
|
+
if (data.toString().trim() !== "") {
|
|
165
|
+
console.log(chalk.blue("→ API Request:"), data.toString());
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
return originalWrite.call(proxyReq, data, ...args);
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
proxyRes: responseInterceptor(
|
|
175
|
+
async (responseBuffer, proxyRes, _req, _res) => {
|
|
176
|
+
const contentType = proxyRes.headers["content-type"] || "";
|
|
177
|
+
|
|
178
|
+
if (!contentType.includes("application/json")) {
|
|
179
|
+
return responseBuffer;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
const body = responseBuffer.toString("utf8");
|
|
184
|
+
console.log(
|
|
185
|
+
chalk.green("← API Response:"),
|
|
186
|
+
JSON.stringify(JSON.parse(body), null, 2),
|
|
187
|
+
);
|
|
188
|
+
console.log(
|
|
189
|
+
chalk.gray("----------------------------------------"),
|
|
190
|
+
);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
console.log(
|
|
193
|
+
chalk.red("← API Response (Parse Error):"),
|
|
194
|
+
responseBuffer.toString(),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return responseBuffer;
|
|
199
|
+
},
|
|
200
|
+
),
|
|
201
|
+
|
|
202
|
+
error: (err) => {
|
|
203
|
+
console.error(chalk.red("Proxy Error:"), err);
|
|
204
|
+
},
|
|
205
|
+
},
|
|
126
206
|
}),
|
|
127
207
|
],
|
|
128
|
-
|
|
129
208
|
notify: false,
|
|
130
209
|
open: false,
|
|
131
210
|
ghostMode: false,
|
|
132
211
|
codeSync: true,
|
|
212
|
+
logLevel: "silent",
|
|
133
213
|
},
|
|
134
214
|
(err, bsInstance) => {
|
|
135
215
|
if (err) {
|
|
136
|
-
console.error("BrowserSync failed to start:", err);
|
|
216
|
+
console.error(chalk.red("BrowserSync failed to start:"), err);
|
|
137
217
|
return;
|
|
138
218
|
}
|
|
139
219
|
|
|
140
220
|
const urls = bsInstance.getOption("urls");
|
|
221
|
+
const localUrl = urls.get("local");
|
|
222
|
+
const externalUrl = urls.get("external");
|
|
223
|
+
const uiUrl = urls.get("ui");
|
|
224
|
+
const uiExtUrl = urls.get("ui-external");
|
|
225
|
+
|
|
226
|
+
console.log("");
|
|
227
|
+
console.log(chalk.green.bold("✔ Ports Configured:"));
|
|
228
|
+
console.log(
|
|
229
|
+
` ${chalk.blue.bold("Frontend (BrowserSync):")} ${chalk.magenta(localUrl)}`,
|
|
230
|
+
);
|
|
231
|
+
console.log(
|
|
232
|
+
` ${chalk.yellow.bold("Backend (PHP Target):")} ${chalk.magenta(
|
|
233
|
+
prismaPhpConfigJson.bsTarget || "http://localhost:80",
|
|
234
|
+
)}`,
|
|
235
|
+
);
|
|
236
|
+
console.log(chalk.gray(" ------------------------------------"));
|
|
237
|
+
|
|
238
|
+
if (externalUrl) {
|
|
239
|
+
console.log(
|
|
240
|
+
` ${chalk.bold("External:")} ${chalk.magenta(externalUrl)}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (uiUrl) {
|
|
245
|
+
console.log(` ${chalk.bold("UI:")} ${chalk.magenta(uiUrl)}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
141
248
|
const out = {
|
|
142
|
-
local:
|
|
143
|
-
external:
|
|
144
|
-
ui:
|
|
145
|
-
uiExternal:
|
|
249
|
+
local: localUrl,
|
|
250
|
+
external: externalUrl,
|
|
251
|
+
ui: uiUrl,
|
|
252
|
+
uiExternal: uiExtUrl,
|
|
146
253
|
};
|
|
147
254
|
|
|
148
255
|
writeFileSync(
|
|
149
256
|
join(__dirname, "bs-config.json"),
|
|
150
|
-
JSON.stringify(out, null, 2)
|
|
257
|
+
JSON.stringify(out, null, 2),
|
|
151
258
|
);
|
|
152
|
-
console.log("
|
|
153
|
-
}
|
|
259
|
+
console.log(`\n${chalk.gray("Press Ctrl+C to stop.")}\n`);
|
|
260
|
+
},
|
|
154
261
|
);
|
|
@@ -175,7 +175,7 @@ class Auth
|
|
|
175
175
|
if (empty($token->{Auth::PAYLOAD_NAME})) return null;
|
|
176
176
|
if (isset($token->exp) && time() >= $token->exp) return null;
|
|
177
177
|
|
|
178
|
-
return $token;
|
|
178
|
+
return $token->{Auth::PAYLOAD_NAME};
|
|
179
179
|
} catch (Exception) {
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
@@ -198,15 +198,20 @@ class Auth
|
|
|
198
198
|
*/
|
|
199
199
|
public function refreshToken(string $jwt, ?string $tokenValidity = null): string
|
|
200
200
|
{
|
|
201
|
-
$
|
|
201
|
+
$decodedData = $this->verifyToken($jwt);
|
|
202
202
|
|
|
203
|
-
if (!$
|
|
203
|
+
if (!$decodedData) {
|
|
204
204
|
throw new InvalidArgumentException("Invalid token.");
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
$expirationTime = $this->calculateExpirationTime($tokenValidity ?? $this->defaultTokenValidity);
|
|
208
|
-
|
|
209
|
-
$
|
|
208
|
+
|
|
209
|
+
$payload = [
|
|
210
|
+
self::PAYLOAD_NAME => $decodedData,
|
|
211
|
+
'exp' => $expirationTime,
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
$newJwt = JWT::encode($payload, $this->secretKey, 'HS256');
|
|
210
215
|
|
|
211
216
|
if (!headers_sent()) {
|
|
212
217
|
$this->setCookies($newJwt, $expirationTime);
|