This commit is contained in:
Patrick Alvin Alcala 2025-11-26 16:51:33 +08:00
parent fec3abd5d8
commit bcb83dfea5
13 changed files with 1542 additions and 4019 deletions

View file

@ -1,25 +1,46 @@
import { ofetch } from 'ofetch' import * as fs from "node:fs";
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api' import { ofetch } from "ofetch";
import * as toml from "toml";
const URL = $backendUrl.get() const config = toml.parse(fs.readFileSync("configs/config.api.toml", "utf-8"));
const RETRY = $requestRetries.get() const URL = config.backend.backend_url;
const CODES = $requestRetryCodes.get() const RETRY = config.request.request_retries;
const CODES = config.request.request_retry_codes;
export default async (api: string, value?: any, value2?: any) => { export default async (
try { api: string,
let fetch value?: string | number,
if (!value2) { value2?: string | number,
if (!value) { ) => {
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES }) try {
} else { let fetch: { [key: string]: unknown };
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES }) if (!value2) {
} if (!value) {
} else { fetch = await ofetch(URL + api, {
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES }) parseResponse: JSON.parse,
} retry: RETRY,
const result = fetch retryDelay: 500,
return [result, null] retryStatusCodes: CODES,
} catch (error) { });
return [[], error] } else {
} fetch = await ofetch(`${URL}${api}/${value}/fetch-data`, {
} parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
}
} else {
fetch = await ofetch(`${URL}${api}/${value}/${value2}/fetch-data`, {
parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
}
const result = fetch;
return [result, null];
} catch (error) {
return [[], error];
}
};

View file

@ -1,37 +1,48 @@
import dayjs from 'dayjs' /** biome-ignore-all lint/suspicious/noExplicitAny: <_> */
import { ofetch } from 'ofetch'
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
import { $tokenExpiration, $tokenName } from '../../../../configs/config.security'
import { encryptRsa } from '../../scripts'
const URL = $backendUrl.get() import dayjs from "dayjs";
const TOKEN_NAME = $tokenName.get() import * as fs from "node:fs";
const TOKEN_EXPIRATION = $tokenExpiration.get() import { ofetch } from "ofetch";
const RETRY = $requestRetries.get() import * as toml from "toml";
const CODES = $requestRetryCodes.get() import { encryptRsa } from "../../scripts/index.ts";
export default async (api: string, body: Object) => { const apiConfig = toml.parse(
const today = new Date() fs.readFileSync("configs/config.api.toml", "utf-8"),
const todayUnix = dayjs(today).unix() );
const expiration = todayUnix + TOKEN_EXPIRATION const securityConfig = toml.parse(
const aes = await encryptRsa(`${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`) fs.readFileSync("configs/config.security.toml", "utf-8"),
);
const hash = `${TOKEN_NAME}=${aes}token` const TOKEN_NAME = securityConfig.token.token_name;
try { const TOKEN_EXPIRATION = securityConfig.token.token_expiration;
await ofetch(URL + api, { const URL = apiConfig.backend.backend_url;
headers: { const RETRY = apiConfig.request.request_retries;
Accept: 'application/json', const CODES = apiConfig.request.request_retry_codes;
'Cache-Control': 'no-cache',
'Dasig-Token': hash, export default async (api: string, body: { [key: string]: unknown }) => {
}, const today = new Date();
retry: RETRY, const todayUnix = dayjs(today).unix();
retryDelay: 500, const expiration = todayUnix + TOKEN_EXPIRATION;
retryStatusCodes: CODES, const aes = await encryptRsa(
method: 'POST', `${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`,
body: body, );
})
return true const hash = `${TOKEN_NAME}=${aes}token`;
} catch { try {
return false await ofetch(URL + api, {
} headers: {
} Accept: "application/json",
"Cache-Control": "no-cache",
"Dasig-Token": hash,
},
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
method: "POST",
body: body,
});
return true;
} catch {
return false;
}
};

View file

@ -1,5 +1,7 @@
/** biome-ignore-all lint/complexity/noUselessFragments: <_> */
import * as fs from "node:fs";
import { type JSXElement, Show } from "solid-js"; import { type JSXElement, Show } from "solid-js";
import { $fontSource } from "../../configs/config.site.ts"; import * as toml from 'toml';
import background1 from "../images/background.avif"; import background1 from "../images/background.avif";
import background2 from "../images/background.webp"; import background2 from "../images/background.webp";
import "../styles/HTML.sass"; import "../styles/HTML.sass";
@ -22,6 +24,7 @@ interface Props {
} }
export default (props: Props) => { export default (props: Props) => {
const config = toml.parse(fs.readFileSync('configs/config.site.toml', 'utf8'))
return ( return (
<> <>
<html lang="en"> <html lang="en">
@ -40,7 +43,7 @@ export default (props: Props) => {
<meta property="og:description" content={props.description} /> <meta property="og:description" content={props.description} />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
<link rel="icon" type="image/svg+xml" href="/favicon.png" /> <link rel="icon" type="image/svg+xml" href="/favicon.png" />
<Show when={$fontSource.get() === "cdn"}> <Show when={config.font.source === "cdn"}>
<link rel="preconnect" href="https://cdn.jsdelivr.net" /> <link rel="preconnect" href="https://cdn.jsdelivr.net" />
</Show> </Show>
<Show when={props.preloadBackground}> <Show when={props.preloadBackground}>

View file

@ -1,16 +1,16 @@
.SILENT: .SILENT:
all: all:
deno install && deno install --allow-scripts=npm:sharp,npm:@parcel/watcher bun install && bun pm trust --all
dev: dev:
deno task dev bun run dev
build: build:
deno task build && PORT=9000 deno run --allow-env --allow-read --allow-net .output/server/index.mjs & bun run build && PORT=9000 node .output/server/index.mjs &
update: update:
deno update bun update
docker: docker:
docker compose up -d docker compose up -d

1389
frontend/bun.lock Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
[backend]
backend_url = "http://localhost:8080"
[request]
request_retries = 3
request_retry_codes = [400, 404, 405, 500, 502]

View file

@ -1,6 +0,0 @@
import { atom } from 'nanostores'
export const $backendUrl = atom('http://localhost:8080')
export const $requestRetries = atom<number>(3)
export const $requestRetryCodes = atom<Array<number>>([400, 404, 405, 500, 502])

View file

@ -1,10 +1,10 @@
import { atom } from 'nanostores' [token]
token_name = "dasig" # output: dasig-token
token_encryption = "rsa"
token_expiration = 9 # seconds
export const $tokenName = atom<string>('dasig') // output: dasig-token [rsa]
export const $tokenEncryption = atom<'rsa'>('rsa') rsa_public_key = '''-----BEGIN PUBLIC KEY-----
export const $tokenExpiration = atom<number>(9) // expires in 9 seconds
export const $rsaPublicKey = atom<string>(`-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA9Aw5Zasdanf2biS69qoQ MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA9Aw5Zasdanf2biS69qoQ
/YZbyIM+LS7LOLNN3ot6nZH1FiTqTNy61ffUA2Y/s3hGz9L0+k6gRu7uGBza6XPU /YZbyIM+LS7LOLNN3ot6nZH1FiTqTNy61ffUA2Y/s3hGz9L0+k6gRu7uGBza6XPU
+iuGdXxZd2mc3lrnPfR6SSllMwGlAVkYpQhmkB19igd8aLUbFiJ3pPKkNocv/yQa +iuGdXxZd2mc3lrnPfR6SSllMwGlAVkYpQhmkB19igd8aLUbFiJ3pPKkNocv/yQa
@ -17,4 +17,4 @@ HvEuAHzUBr+GJM9w4/LF1mQSsmblB8q5S7qNaminYAw6wm35lRy7ZlIbJQlj/EyL
lCKWBbUEHkjzRFCoun9VVUc0guQTsTbchPD7Rgzg3SBK3Gws39n12WQPc7jKto0H lCKWBbUEHkjzRFCoun9VVUc0guQTsTbchPD7Rgzg3SBK3Gws39n12WQPc7jKto0H
N39sJnNzllXw41gKRy9b2uYuaVYaQ0sjrFJ8ITuyO9NDDaEdeBqBBTtbRp2i0O4K N39sJnNzllXw41gKRy9b2uYuaVYaQ0sjrFJ8ITuyO9NDDaEdeBqBBTtbRp2i0O4K
tvT2kItEEnVzjNutUatVOWcCAwEAAQ== tvT2kItEEnVzjNutUatVOWcCAwEAAQ==
-----END PUBLIC KEY-----`) -----END PUBLIC KEY-----'''

View file

@ -0,0 +1,11 @@
[website]
name = "Dasig"
description = "An architectural framework for pure speed fullstack development"
[font]
name = "inter"
source = "cdn" # cdn or local
[copyright]
name = "Pat Alcala"
year = 2025

View file

@ -1,10 +0,0 @@
import { atom } from 'nanostores'
export const $websiteName = atom<string>('Dasig')
export const $websiteDescription = atom<string>('A template for next level speed (Solid Version)')
export const $font = atom<string>('inter')
export const $fontSource = atom<'cdn'| 'local'>('cdn')
export const $companyName = atom<string>('Pat Alcala')
export const $copyRightYear = atom<number>(2025)

3922
frontend/deno.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,14 +13,13 @@
"@solidjs/start": "^1.1.0", "@solidjs/start": "^1.1.0",
"consola": "^3.4.2", "consola": "^3.4.2",
"dayjs": "^1.11.19", "dayjs": "^1.11.19",
"eciesjs": "^0.4.16",
"jsencrypt": "^3.5.4", "jsencrypt": "^3.5.4",
"nanostores": "^1.1.0", "nanostores": "^1.1.0",
"ofetch": "^1.5.1", "ofetch": "^1.5.1",
"png-to-ico": "^3.0.1",
"sharp": "^0.34.5", "sharp": "^0.34.5",
"solid-icons": "^1.1.0", "solid-icons": "^1.1.0",
"solid-js": "^1.9.10", "solid-js": "^1.9.10",
"toml": "^3.0.0",
"vinxi": "^0.5.7", "vinxi": "^0.5.7",
"yargs": "^18.0.0" "yargs": "^18.0.0"
}, },
@ -31,5 +30,8 @@
"@biomejs/biome": "^2.3.7", "@biomejs/biome": "^2.3.7",
"@types/node": "^24.10.1", "@types/node": "^24.10.1",
"sass-embedded": "^1.93.3" "sass-embedded": "^1.93.3"
} },
"trustedDependencies": [
"@parcel/watcher"
]
} }

View file

@ -1,11 +1,29 @@
// deno-lint-ignore-file jsx-no-children-prop // deno-lint-ignore-file jsx-no-children-prop
import { createHandler, StartServer } from '@solidjs/start/server';
import { HTML } from '../@dasig/index.ts';
import { $companyName, $font, $websiteDescription, $websiteName } from '../configs/config.site.ts';
const websiteName = $websiteName.get() import * as fs from "node:fs";
const websiteDescription = $websiteDescription.get() // import { $companyName, $font, $websiteDescription, $websiteName } from '../configs/config.site.ts';
const author = $companyName.get() import { createHandler, StartServer } from "@solidjs/start/server";
const font = $font.get() import * as toml from "toml";
import { HTML } from "../@dasig/index.ts";
export default createHandler(() => <StartServer document={({ assets, children, scripts }) => <HTML name={websiteName} description={websiteDescription} author={author} children={children} assets={assets} scripts={scripts} font={font} />} />) const config = toml.parse(fs.readFileSync("configs/config.site.toml", "utf8"));
const websiteName = config.website.name;
const websiteDescription = config.website.description;
const author = config.copyright.name;
const font = config.font.name;
export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => (
<HTML
name={websiteName}
description={websiteDescription}
author={author}
children={children}
assets={assets}
scripts={scripts}
font={font}
/>
)}
/>
));