Skip to content

Commit ce8a31f

Browse files
committed
support api for local development
1 parent 6221df8 commit ce8a31f

7 files changed

Lines changed: 17 additions & 12 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

src/.DS_Store

0 Bytes
Binary file not shown.

src/components/app-head.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ const AppHeader = ({ name = "oomph", icon = "/favicon.png" }) => {
4141
</head>
4242
);
4343
};
44-
export default async ({ name, icon }) => {
44+
export default async ({ req, attributes }) => {
4545
let manifest = { name: "oomph", icon: "/favicon.png" };
4646
const manifest_path = `${window._cwd}/src/public/manifest.json`;
47-
console.log(manifest_path, "manifest path");
48-
console.log(await exists(manifest_path), "manifest exists");
47+
// console.log(manifest_path, "manifest path");
48+
// console.log(await exists(manifest_path), "manifest exists");
4949

5050
try {
5151
if (await exists(manifest_path)) {

src/middleware/api.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ const api_middleware = async (request) => {
7777
oomph.logger.info({ ...data });
7878
}
7979

80-
let api_path = `${app_path}/${apiPath}${request.method.toLowerCase()}.js`;
80+
const api_src = `${app_path}/${apiPath}${request.method.toLowerCase()}.js`;
81+
82+
let api_path = `file:///${api_src}`;
8183

8284
// this is to be able to handle the production enviroment
8385
if (Deno.env.get("env") === "production") {
84-
api_path = `app/${api_path}`;
86+
api_path = `app/${api_src}`;
8587
}
8688

8789
const { default: apiMethod } = await import(api_path);

src/middleware/html.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ const html_middleware = async (req, isProd) => {
3131
? await Deno.readTextFile(tempSrc)
3232
: await exists(paramPage)
3333
? await Deno.readTextFile(paramPage)
34-
: `<h1>Error In Page</h1>`;
34+
: `<app-head/><div class="w-screen h-screen flex items-center justify-center">To get lost is to learn the way </h1>`;
3535

3636
const components = getComponents(src);
3737

3838
if (components && components.length > 0) {
39-
src = await compileDoc(src, components, paths, isProd);
39+
src = await compileDoc(src, components, paths, isProd, req);
4040
}
4141

4242
if (!isProd) {

src/middleware/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const script_middleware = async (req, isProd) => {
1+
const script_middleware = async (req) => {
22
const app_path = window._app;
33
const { pathname: _pathname } = new URL(req.url);
44
console.log(_pathname);
@@ -8,7 +8,7 @@ const script_middleware = async (req, isProd) => {
88
let res = await import(`file:///${app_path}${_pathname}`);
99

1010
// this is to support deployment to a linux enviroment
11-
if (Deno.build.os !== "windows" && isProd) {
11+
if (Deno.env.get("env") === "production") {
1212
res = await import(`app/${app_path}${_pathname}`);
1313
}
1414

src/middleware/utls/components/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getGlobalElementPath = (element_name) => {
1414
return `../../../components/${element_name}.jsx`;
1515
};
1616
const globalElements = ["app-head"];
17-
export const compileDoc = async (html, elements, path, isProd) => {
17+
export const compileDoc = async (html, elements, path, isProd, req) => {
1818
let new_doc = html;
1919
let shell_doc;
2020
const app_source = window._cwd;
@@ -65,7 +65,7 @@ export const compileDoc = async (html, elements, path, isProd) => {
6565

6666
let element_src;
6767
for (let { path, included } of paths) {
68-
console.log(path, await exists(path));
68+
6969
if (await exists(path) || included) {
7070
if (included) {
7171
element_src = await import(path);
@@ -90,7 +90,10 @@ export const compileDoc = async (html, elements, path, isProd) => {
9090
});
9191
}
9292

93-
new_doc = new_doc.replace(element, await element_src.default(atrributes));
93+
const element_component = await element_src.default({req, atrributes})
94+
95+
new_doc = new_doc.replace(element,element_component );
96+
9497
}
9598
}));
9699

0 commit comments

Comments
 (0)