Skip to content

Commit eb61384

Browse files
authored
fix: added static files to allowed paths (#24)
1 parent 6272df1 commit eb61384

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pgdata/
55
debug.log
66
.zed/
77
.vscode/
8+
public/

.zed/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"command": "deno",
4-
"args": ["run", "-A", "--watch", "--watch-exclude=.inspatial", "main.ts"],
4+
"args": ["run", "-A", "main.ts"],
55
"cwd": "$ZED_WORKTREE_ROOT/examples/basic",
66
"label": "Example: Basic",
77
"allow_concurrent_runs": false,

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",

extensions/auth/auth-handler.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export class AuthHandler {
1212
this.#inCloud = inCloud;
1313
}
1414

15-
#allowedPaths: Set<string> = new Set();
15+
#allowedPaths: Set<RegExp> = new Set();
1616
#allowedActions: Map<string, Set<string>> = new Map();
1717

18-
get allowedPaths(): string[] {
18+
get allowedPaths(): RegExp[] {
1919
return Array.from(this.#allowedPaths);
2020
}
2121

@@ -31,8 +31,8 @@ export class AuthHandler {
3131
);
3232
return actions;
3333
}
34-
allowPath(path: string): void {
35-
this.#allowedPaths.add(path);
34+
allowPath(match: RegExp): void {
35+
this.#allowedPaths.add(match);
3636
}
3737
allowAction(group: string, action: string): void {
3838
if (!this.#allowedActions.has(group)) {
@@ -41,17 +41,19 @@ export class AuthHandler {
4141
this.#allowedActions.get(group)?.add(action);
4242
}
4343

44-
disallowPath(path: string): void {
45-
this.#allowedPaths.delete(path);
44+
disallowPath(match: RegExp): void {
45+
this.#allowedPaths.delete(match);
4646
}
4747
disallowAction(group: string, action: string): void {
4848
if (this.#allowedActions.has(group)) {
4949
this.#allowedActions.get(group)?.delete(action);
5050
}
5151
}
5252
isPathAllowed(path: string): boolean {
53-
if (this.#allowedPaths.has(path)) {
54-
return true;
53+
for (const match of this.#allowedPaths) {
54+
if (match.test(path)) {
55+
return true;
56+
}
5557
}
5658
return false;
5759
}

extensions/auth/entry-types/user/user.type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export interface User extends EntryBase {
3131
fullName?: string;
3232
/**
3333
* **Role** (ChoicesField)
34-
* @type {'systemAdmin' | 'basic' | 'gedcomUser'}
34+
* @type {'systemAdmin' | 'basic'}
3535
*/
36-
role?: "systemAdmin" | "basic" | "gedcomUser";
36+
role?: "systemAdmin" | "basic";
3737
/**
3838
* **Profile Picture** (ImageField)
3939
* @description The user's profile picture

extensions/auth/mod.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import { authMiddleware } from "#extensions/auth/auth-middleware.ts";
88
import { userSessionEntry } from "./entry-types/user-session/user-session-entry.ts";
99
import { authSettings } from "./settings-types/auth-settings/auth-settings.ts";
1010
import { userEntry } from "./entry-types/user/user-entry.ts";
11+
import { staticFilesHandler } from "~/static/staticPathHandler.ts";
12+
import { apiPathHandler } from "~/api/api-handler.ts";
1113

1214
export const authCloudExtension: CloudExtension = new CloudExtension("auth", {
1315
label: "Auth",
1416
description: "Auth extension",
1517
install(app, config) {
1618
const handler = new AuthHandler(app);
17-
handler.allowPath("/api");
19+
handler.allowPath(apiPathHandler.match);
20+
handler.allowPath(staticFilesHandler.match);
1821

1922
for (const group of app.actionGroups.values()) {
2023
for (const action of group.actions.values()) {

src/api/api-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { HandlerResponse, PathHandler } from "~/app/path-handler.ts";
22
import { raiseServerException, Redirect } from "~/app/server-exception.ts";
33

4-
export const apiPathHandeler: PathHandler = {
4+
export const apiPathHandler: PathHandler = {
55
name: "api",
66
description: "api",
77
match: /^\/api/,

src/base-extension/base-extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CloudExtension } from "~/app/cloud-extension.ts";
22
import { corsMiddleware } from "~/base-extension/middleware/cors.ts";
33

44
import { inLiveMiddleware } from "~/base-extension/middleware/inLive.ts";
5-
import { apiPathHandeler } from "~/api/api-handler.ts";
5+
import { apiPathHandler } from "~/api/api-handler.ts";
66
import { systemSettings } from "~/base-extension/settings-types/systemSettings.ts";
77
import { cloudActions } from "./actions/dev-actions.ts";
88
import { inTask } from "~/in-queue/entry-types/in-task/in-task.ts";
@@ -19,6 +19,13 @@ export const baseExtension = new CloudExtension("cloud", {
1919
app.static.staticFilesRoot = normalizePath(path);
2020
} catch (e) {
2121
if (e instanceof Deno.errors.NotFound) {
22+
if (config.publicRoot === "./public") {
23+
Deno.mkdirSync(config.publicRoot, { recursive: true });
24+
app.static.staticFilesRoot = normalizePath(
25+
Deno.realPathSync(config.publicRoot),
26+
);
27+
return;
28+
}
2229
raiseCloudException(
2330
`Public root directory not found: ${config.publicRoot}`,
2431
);
@@ -124,7 +131,7 @@ export const baseExtension = new CloudExtension("cloud", {
124131
settingsTypes: [systemSettings],
125132
entryTypes: [inTask],
126133
middleware: [corsMiddleware, inLiveMiddleware],
127-
pathHandlers: [apiPathHandeler, staticFilesHandler],
134+
pathHandlers: [apiPathHandler, staticFilesHandler],
128135
roles: [{
129136
roleName: "basic",
130137
label: "Basic User",

0 commit comments

Comments
 (0)