@bananacool467/authtics-host 0.0.2-beta.4 → 0.1.2

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/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # Authtics Host
2
2
 
3
- Version 0.0.2-beta.4
3
+ Version 0.1.2
4
4
  License: MIT
5
5
 
6
- **(NOTE: This version is in BETA, bugs are expected)**
7
-
8
6
  Authtics Host is a framework inspired by Next.js. Authtics Host supports SSR (Server-Side Rendering) and uses esbuild.
9
7
 
10
- **(NOTE: The short name for Authtics Host is HostJS)**
8
+ **(NOTE: The short name for Authtics Host is HostJS or Host.js)**
11
9
 
12
10
  ## Setting Up
13
11
 
@@ -100,17 +98,24 @@ export default defineConfig({
100
98
 
101
99
  `client/app.tsx` should look like:
102
100
  ```tsx
103
- import { Route } from "@bananacool467/authtics-host";
101
+ import { Route, RouteMap } from "@bananacool467/authtics-host";
104
102
  import Index from "./pages/index";
105
103
 
106
104
  export default function App() {
107
105
  return (
108
- <>
106
+ <RouteMap>
109
107
  <Route at="/" statusCode={200} page={Index} />
110
- </>
108
+ </RouteMap>
111
109
  )
112
110
  }
113
111
  ```
112
+ **(NOTE: You can change the `statusCode` to anything you want, the property is optional, it either gives 404 or 200 if the `statusCode` is missing.)**
113
+
114
+ **(NOTE: To make an 404 page you can use:**
115
+ ```tsx
116
+ <Route statusCode={404} page={NotFound} />
117
+ ```
118
+ **)**
114
119
 
115
120
  `client/pages/index.tsx` should look like:
116
121
  ```tsx
@@ -142,6 +147,22 @@ node --experimental-strip-types index.ts
142
147
 
143
148
  Then when you run your project, you will get a page just saying **"Hello, World!"** and you should see a clickable Developer Panel at the bottom-right.
144
149
 
150
+ ## About The Developer Panel
151
+
152
+ The Developer Panel is what you could use to help you debug your code. The Developer Panel has **7 tabs**:
153
+
154
+ **Console** — Shows current logs
155
+ **Route** — Shows information about the current route
156
+ **Webpage Info** — Shows information about the website/webpage
157
+ **Network** — Shows the current ping and shows sent fetches from the client and shows received from the server after fetching
158
+ **Client Info** — Shows information about your client's User Agent, OS and FPS
159
+ **About Host** — Shows the current version of Authtics Host
160
+ **Server Info** — Shows how much heap was used and how much CPU was used on the server and how much requests there were and how much users are currently on the site and how long the site has been up
161
+
162
+ The information the Developer Panel shows is just your **DAT** (Developer Access Token).
163
+
164
+ **(NOTE: If you do not set DAT restriction (Which will be explained on how to set it up in the next section), you will only get access to the Console and Network tabs)**
165
+
145
166
  ## Developer Panel Notes And Warnings And DAT (Developer Access Token)
146
167
 
147
168
  A DAT (Developer Access Token) is your token that is used to access the Developer Panel.
package/dist/cli.js CHANGED
@@ -331,7 +331,6 @@ async function start() {
331
331
  config.autoPage = true;
332
332
  if (config.autoFile == null)
333
333
  config.autoFile = true;
334
- console.log(JSON.stringify(config));
335
334
  const PORT = config.port ?? 3000;
336
335
  const showPanel = config.devMode !== false;
337
336
  const autoPaging = config.autoPage !== false;
@@ -411,7 +410,7 @@ async function start() {
411
410
  const htmlPath = pagesDir ? path.join(pagesDir, `${urlPath}.html`) : undefined;
412
411
  if (tsxPath && fs.existsSync(tsxPath)) {
413
412
  try {
414
- const html = await renderPage(tsxPath, url, actuallyShowPanel, compiler, hotReload, autoPaging);
413
+ const html = await renderPage(tsxPath, url, actuallyShowPanel, compiler, hotReload, autoPaging, config.autoPageDir, (routes.get("APP_TSX") || ""));
415
414
  res.setHeader("Content-Type", "text/html");
416
415
  return res.end(html);
417
416
  }
@@ -430,7 +429,7 @@ async function start() {
430
429
  const appPath = path.join(process.cwd(), appTsxPath);
431
430
  if (fs.existsSync(appPath)) {
432
431
  try {
433
- const html = await renderPage(appPath, url, actuallyShowPanel, compiler, hotReload, autoPaging);
432
+ const html = await renderPage(appPath, url, actuallyShowPanel, compiler, hotReload, autoPaging, config.autoPageDir, (routes.get("APP_TSX") || ""));
434
433
  res.setHeader("Content-Type", "text/html");
435
434
  return res.end(html);
436
435
  }
@@ -444,7 +443,7 @@ async function start() {
444
443
  const notFoundPath = path.join(__dirname, '404.js');
445
444
  if (fs.existsSync(notFoundPath)) {
446
445
  try {
447
- let html = await renderPage(notFoundPath, url, actuallyShowPanel, compiler, hotReload, autoPaging);
446
+ let html = await renderPage(notFoundPath, url, actuallyShowPanel, compiler, hotReload, autoPaging, config.autoPageDir, (routes.get("APP_TSX") || ""));
448
447
  res.setHeader("Content-Type", "text/html");
449
448
  res.writeHead(404);
450
449
  html = html.replace("<script>", "<script>\nwindow.__status_code__ = 404;");
package/dist/devPanel.js CHANGED
@@ -177,7 +177,11 @@ export default function DevPanel() {
177
177
  const [hostName, setHostName] = useState(undefined);
178
178
  const [protocol, setProtocol] = useState(undefined);
179
179
  const [path, setPath] = useState(undefined);
180
+ const contextMenuTimeoutMobile = useRef(undefined);
181
+ const [cursorPosition, setCursorPosition] = useState({ x: 0, y: 0 });
182
+ const [contextMenuShown, setContextMenuShown] = useState(false);
180
183
  const [isSsr, setIsSsr] = useState(false);
184
+ const datRestrictionMissingRef = useRef(true);
181
185
  const cpuUsage = useRef(0);
182
186
  const heapUsage = useRef(0);
183
187
  const [datMatch, setDatMatch] = useState(false);
@@ -252,7 +256,6 @@ export default function DevPanel() {
252
256
  setDatMatch(data.isMatching);
253
257
  if (!data.isMatching) {
254
258
  doc?.getElementById('authtics-dev-panel-root')?.remove();
255
- return;
256
259
  }
257
260
  const resp2 = await fetch('/__authtics_host_apis__/get-dat-restriction-missing', {
258
261
  method: 'POST',
@@ -262,8 +265,11 @@ export default function DevPanel() {
262
265
  if (resp2.status === 200) {
263
266
  const data = await resp2.json();
264
267
  setDatRestrictionMissing(!data.enabled);
268
+ datRestrictionMissingRef.current = !data.enabled;
269
+ return "";
265
270
  }
266
271
  }
272
+ return "";
267
273
  };
268
274
  const isSSR = async () => {
269
275
  const resp = await fetch('/__authtics_host_apis__/get-is-ssr', {
@@ -355,22 +361,36 @@ export default function DevPanel() {
355
361
  };
356
362
  setTimeout(async () => {
357
363
  await getDatMatching();
358
- if (datRestrictionMissing === false) {
359
- getPath();
360
- getCompilerType();
361
- getHttpVersion();
362
- isSSR();
363
- userSettings();
364
- getHostVersion();
365
- setInterval(() => {
366
- getUsage();
367
- }, 250);
368
- setInterval(() => {
369
- update();
370
- }, 500);
371
- }
364
+ setTimeout(() => {
365
+ if (datRestrictionMissingRef.current === false) {
366
+ getPath();
367
+ getCompilerType();
368
+ getHttpVersion();
369
+ isSSR();
370
+ userSettings();
371
+ getHostVersion();
372
+ setInterval(() => {
373
+ getUsage();
374
+ }, 250);
375
+ setInterval(() => {
376
+ update();
377
+ }, 500);
378
+ }
379
+ }, 250);
372
380
  }, 250);
373
381
  }, []);
382
+ const datTouchStart = (e) => {
383
+ e.preventDefault();
384
+ setCursorPosition({ x: e.clientX || e.touches[0].clientX, y: e.clientY || e.touches[0].clientY });
385
+ contextMenuTimeoutMobile.current = setTimeout(() => {
386
+ setContextMenuShown(true);
387
+ clearTimeout(contextMenuTimeoutMobile.current);
388
+ }, 1000);
389
+ };
390
+ const datTouchEnd = (e) => {
391
+ e.preventDefault();
392
+ clearTimeout(contextMenuTimeoutMobile.current);
393
+ };
374
394
  const restart = async () => {
375
395
  const resp = await fetch('/__authtics_host_apis__/restart', {
376
396
  method: 'POST',
@@ -492,7 +512,7 @@ export default function DevPanel() {
492
512
  catch (error) {
493
513
  }
494
514
  window.addEventListener('authtics:log', handler);
495
- setStatus(window.__status_code__ | 200);
515
+ setInterval(() => setStatus(window.__status_code__ || 200), 1000);
496
516
  setPathName(window.location.pathname);
497
517
  setHostName(window.location.hostname);
498
518
  setDoc(document);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { defineConfig } from './config.js';
2
2
  import App from './cli.js';
3
- import Route from './route.js';
4
- export { App, Route, defineConfig };
3
+ import { Route } from './route.js';
4
+ import { RouteMap } from './route.js';
5
+ export { App, Route, RouteMap, defineConfig };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { defineConfig } from './config.js';
2
2
  import App from './cli.js';
3
- import Route from './route.js';
4
- export { App, Route, defineConfig };
3
+ import { Route } from './route.js';
4
+ import { RouteMap } from './route.js';
5
+ export { App, Route, RouteMap, defineConfig };
@@ -1,3 +1,3 @@
1
1
  export type CompilerType = 'esbuild' | 'babel';
2
2
  export declare function findFileUpwards(startDir: string, relativePath: string): string | null;
3
- export declare function renderPage(tsxPath: string, reqUrl?: string, showPanel?: boolean, compiler?: CompilerType, hotReload?: boolean, autoPaging?: boolean): Promise<string>;
3
+ export declare function renderPage(tsxPath: string, reqUrl?: string, showPanel?: boolean, compiler?: CompilerType, hotReload?: boolean, autoPaging?: boolean, autoPageDir?: string, appDir?: string): Promise<string>;
@@ -75,26 +75,20 @@ function resolveDevPanelPath() {
75
75
  return null;
76
76
  }
77
77
  const devPanelPath = resolveDevPanelPath();
78
- function resolveTemplate(tsxPath) {
79
- const pagesDir = path.join(process.cwd(), "pages");
80
- let dir = path.dirname(tsxPath);
81
- while (true) {
82
- const candidate = path.join(dir, "_template.html");
83
- if (fs.existsSync(candidate))
84
- return candidate;
85
- if (dir === pagesDir || dir === path.dirname(pagesDir))
86
- break;
87
- const parent = path.dirname(dir);
88
- if (parent === dir)
89
- break;
90
- dir = parent;
78
+ function resolveTemplate(appDir, autoPageDir, autoPaging) {
79
+ let nextToCli;
80
+ if (autoPaging) {
81
+ nextToCli = path.join(process.cwd(), autoPageDir || "", "_template.html");
91
82
  }
92
- return null;
83
+ else {
84
+ nextToCli = path.join(process.cwd(), appDir || "", "../", "_template.html");
85
+ }
86
+ return nextToCli;
93
87
  }
94
88
  function buildHtml(opts) {
95
89
  const { pageHtml, clientCode, devPanelContainer, templatePath, hotReload } = opts;
96
90
  const hmrScript = hotReload ? HMR_SCRIPT : '';
97
- if (templatePath) {
91
+ if (templatePath && fs.existsSync(templatePath)) {
98
92
  let template = fs.readFileSync(templatePath, "utf-8");
99
93
  const contentTag = /<authtics_host_content\s*\/>/i;
100
94
  if (contentTag.test(template)) {
@@ -146,13 +140,13 @@ const HMR_SCRIPT = `
146
140
  })();
147
141
  </script>
148
142
  `;
149
- export async function renderPage(tsxPath, reqUrl, showPanel = true, compiler = 'esbuild', hotReload = false, autoPaging = true) {
143
+ export async function renderPage(tsxPath, reqUrl, showPanel = true, compiler = 'esbuild', hotReload = false, autoPaging = true, autoPageDir, appDir) {
150
144
  ensureTempDirs();
151
145
  if (!fs.existsSync(tsxPath)) {
152
146
  throw new Error(`renderPage: source file not found: ${tsxPath}`);
153
147
  }
154
148
  const usesDevPanel = showPanel && devPanelPath !== null;
155
- const templatePath = resolveTemplate(tsxPath);
149
+ const templatePath = resolveTemplate(appDir, autoPageDir, autoPaging);
156
150
  const tempPath = tempFileForTsx(tsxPath);
157
151
  const serverCjsPath = tempPath.replace(/\.json$/, ".server.cjs");
158
152
  let clientCode;
package/dist/route.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export default function Route({ page, statusCode, at }: {
1
+ export declare function RouteMap({ children }: {
2
+ children?: React.ReactNode;
3
+ }): import("react/jsx-runtime").JSX.Element;
4
+ export declare function Route({ page, statusCode, at }: {
2
5
  page: Function;
3
6
  statusCode?: number;
4
7
  at?: string;
package/dist/route.js CHANGED
@@ -1,30 +1,55 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- export default function Route({ page, statusCode, at }) {
4
- const Page = page;
5
- const [pathName, setPathName] = useState("");
6
- const [is404, setIs404] = useState(false);
7
- const [thisPassed, setThisPassed] = useState(false);
2
+ import { useEffect, useState, useRef } from "react";
3
+ import NotFound from "./404.js";
4
+ export function RouteMap({ children }) {
5
+ const childArray = useRef(children);
6
+ const [path, setPath] = useState('');
7
+ const matched = useRef(null);
8
+ const [MatchedEl, setMatchedEl] = useState(null);
9
+ const [currentlyAwaiting, setCurrentlyAwaiting] = useState(true);
10
+ const [At404, setAt404] = useState(false);
8
11
  useEffect(() => {
9
- setPathName(window.location.pathname);
12
+ setPath(window.location.pathname);
10
13
  }, []);
11
14
  useEffect(() => {
12
- if (window.___passed == true)
13
- return;
14
- if (at == "" || at == undefined) {
15
- window.__status_code__ = statusCode || 404;
16
- setIs404(true);
15
+ const childrenToProcess = Array.isArray(childArray.current)
16
+ ? childArray.current
17
+ : [childArray.current];
18
+ childrenToProcess.forEach((child) => {
19
+ if (child?.props?.at === path) {
20
+ matched.current = child.props;
21
+ }
22
+ });
23
+ if (!matched.current) {
24
+ childrenToProcess.forEach((child) => {
25
+ if (child?.props?.at === undefined) {
26
+ matched.current = child.props;
27
+ setAt404(true);
28
+ }
29
+ });
30
+ }
31
+ setCurrentlyAwaiting(false);
32
+ }, [path]);
33
+ useEffect(() => {
34
+ if (matched.current && !At404) {
35
+ setMatchedEl(() => matched.current.page);
36
+ window.__status_code__ = matched.current.statusCode || 200;
37
+ }
38
+ else if (At404) {
39
+ setMatchedEl(() => matched.current.page);
40
+ window.__status_code__ = matched.current.statusCode || 404;
17
41
  }
18
42
  else {
19
- if (pathName == at) {
20
- window.__status_code__ = statusCode || 200;
21
- }
22
- else {
23
- return;
24
- }
43
+ setMatchedEl(() => NotFound);
44
+ window.__status_code__ = 404;
25
45
  }
26
- window.___passed = true;
27
- setThisPassed(true);
28
- }, [pathName]);
29
- return (_jsx(_Fragment, { children: thisPassed ? (_jsx(_Fragment, { children: _jsx(Page, {}) })) : (_jsx(_Fragment, {})) }));
46
+ }, [path]);
47
+ if (matched.current && MatchedEl)
48
+ return _jsx(MatchedEl, {});
49
+ if (currentlyAwaiting)
50
+ return _jsx(_Fragment, {});
51
+ return _jsx(NotFound, {});
52
+ }
53
+ export function Route({ page, statusCode, at }) {
54
+ return (_jsx(_Fragment, {}));
30
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananacool467/authtics-host",
3
- "version": "0.0.2-beta.4",
3
+ "version": "0.1.2",
4
4
  "description": "A Next.js-inspired SSR framework for Node.js with TypeScript and JSX support.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -36,7 +36,8 @@
36
36
  "hot-reload",
37
37
  "dev",
38
38
  "developer",
39
- "HostJS"
39
+ "HostJS",
40
+ "Host.js"
40
41
  ],
41
42
  "author": "bananacool467",
42
43
  "license": "MIT",