create-colonel 0.1.5 → 0.1.6
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/package.json +1 -1
- package/template/package.json +2 -2
- package/template/resources/views/base/index.ejs +1 -1
- package/template/src/app/Http/Controllers/AppController.ts +8 -2
- package/template/src/app/Http/Controllers/Controller.ts +22 -0
- package/template/src/app/Services/AppInfoService.ts +8 -1
- package/template/src/bootstrap/server.ts +10 -1
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "colonel-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": true,
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"upgrade:colonel": "bun add @coloneldev/framework@latest"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@coloneldev/framework": "^0.1.
|
|
11
|
+
"@coloneldev/framework": "^0.1.5",
|
|
12
12
|
"ejs": "^5.0.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
</p>
|
|
135
135
|
<div class="cta">
|
|
136
136
|
<a class="btn btn-primary" href="/users">View User Route</a>
|
|
137
|
-
<a class="btn btn-secondary" href="https://github.
|
|
137
|
+
<a class="btn btn-secondary" href="<%= docsUrl || 'https://gwhitdev.github.io/colonel-framework/' %>" target="_blank" rel="noreferrer">Open Documentation</a>
|
|
138
138
|
</div>
|
|
139
139
|
|
|
140
140
|
<div class="grid">
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HttpRequest } from "@coloneldev/framework";
|
|
1
2
|
import Controller from './Controller';
|
|
2
3
|
import { AppInfoService } from '../../Services/AppInfoService';
|
|
3
4
|
|
|
@@ -8,12 +9,17 @@ export class AppController extends Controller {
|
|
|
8
9
|
super();
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
index(): Record<string, any> {
|
|
12
|
+
index(req: HttpRequest): Record<string, any> {
|
|
13
|
+
const previousVisits = this.sessionGet<number>(req, "visits") ?? 0;
|
|
14
|
+
const visits = previousVisits + 1;
|
|
15
|
+
this.sessionPut(req, "visits", visits);
|
|
16
|
+
|
|
12
17
|
return [
|
|
13
18
|
'base/index',
|
|
14
19
|
{
|
|
15
20
|
"titleData": this.appInfoService.welcomeTitle(),
|
|
16
|
-
|
|
21
|
+
"docsUrl": this.appInfoService.documentationUrl(),
|
|
22
|
+
"footerData": `Session visits: ${visits}`,
|
|
17
23
|
},
|
|
18
24
|
]
|
|
19
25
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { HttpRequest, Session } from "@coloneldev/framework";
|
|
2
|
+
|
|
1
3
|
export default class Controller {
|
|
2
4
|
constructor() {
|
|
3
5
|
// Base constructor logic can be added here if needed
|
|
@@ -6,4 +8,24 @@ export default class Controller {
|
|
|
6
8
|
health(): Record<string, string> {
|
|
7
9
|
return { status: "ok" };
|
|
8
10
|
}
|
|
11
|
+
|
|
12
|
+
protected requireSession(req: HttpRequest): Session {
|
|
13
|
+
if (!req.session) {
|
|
14
|
+
throw new Error("Session is not enabled for this request");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return req.session;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected sessionGet<T = unknown>(req: HttpRequest, key: string): T | undefined {
|
|
21
|
+
return this.requireSession(req).get<T>(key);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected sessionPut(req: HttpRequest, key: string, value: unknown): void {
|
|
25
|
+
this.requireSession(req).set(key, value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected sessionForget(req: HttpRequest, key: string): void {
|
|
29
|
+
this.requireSession(req).forget(key);
|
|
30
|
+
}
|
|
9
31
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export class AppInfoService {
|
|
2
|
-
constructor(
|
|
2
|
+
constructor(
|
|
3
|
+
private appName: string,
|
|
4
|
+
private docsUrl: string = "https://gwhitdev.github.io/colonel-framework/"
|
|
5
|
+
) {}
|
|
3
6
|
|
|
4
7
|
welcomeTitle(): string {
|
|
5
8
|
return `Welcome to ${this.appName}`;
|
|
6
9
|
}
|
|
10
|
+
|
|
11
|
+
documentationUrl(): string {
|
|
12
|
+
return this.docsUrl;
|
|
13
|
+
}
|
|
7
14
|
}
|
|
@@ -13,11 +13,20 @@ const publicRoot = path.resolve(import.meta.dir, "..", "..", "public");
|
|
|
13
13
|
const controllerRoot = path.resolve(import.meta.dir, "..", "app", "Http", "Controllers");
|
|
14
14
|
const container = new Container();
|
|
15
15
|
|
|
16
|
-
container.singleton(
|
|
16
|
+
container.singleton(
|
|
17
|
+
AppInfoService,
|
|
18
|
+
() => new AppInfoService(
|
|
19
|
+
process.env.appName ?? "Colonel",
|
|
20
|
+
process.env.COLONEL_DOCS_URL ?? "https://gwhitdev.github.io/colonel-framework/"
|
|
21
|
+
)
|
|
22
|
+
);
|
|
17
23
|
|
|
18
24
|
export const server = () => {
|
|
19
25
|
const Colonel = new Kernel(webRouter, [], {
|
|
20
26
|
viewsRoot,
|
|
27
|
+
session: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
},
|
|
21
30
|
controllerResolver: async (name: string) => {
|
|
22
31
|
const modulePath = `${controllerRoot}/${name}.ts`;
|
|
23
32
|
const mod = await import(modulePath);
|