@batijs/cli 0.0.195 → 0.0.197

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.
Files changed (38) hide show
  1. package/dist/boilerplates/@batijs/auth0/files/$.env.js +5 -9
  2. package/dist/boilerplates/@batijs/auth0/files/$README.md.js +8 -17
  3. package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +100 -0
  4. package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +16 -0
  5. package/dist/boilerplates/@batijs/eslint/files/.eslintrc.json +15 -2
  6. package/dist/boilerplates/@batijs/express/files/$package.json.js +8 -9
  7. package/dist/boilerplates/@batijs/express/files/express-entry.ts +51 -144
  8. package/dist/boilerplates/@batijs/express/types/express-entry.d.ts +5 -0
  9. package/dist/boilerplates/@batijs/fastify/files/$package.json.js +6 -10
  10. package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +63 -149
  11. package/dist/boilerplates/@batijs/fastify/types/fastify-entry.d.ts +6 -0
  12. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +8 -0
  13. package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseAdmin.ts +2 -1
  14. package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +72 -0
  15. package/dist/boilerplates/@batijs/firebase-auth/types/libs/firebaseAdmin.d.ts +2 -1
  16. package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +4 -0
  17. package/dist/boilerplates/@batijs/h3/files/$package.json.js +4 -6
  18. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +36 -175
  19. package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +5 -0
  20. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +7 -3
  21. package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +40 -60
  22. package/dist/boilerplates/@batijs/hattip/types/hattip-entry.d.ts +1 -0
  23. package/dist/boilerplates/@batijs/hono/files/$package.json.js +5 -3
  24. package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +54 -116
  25. package/dist/boilerplates/@batijs/hono/types/hono-entry.d.ts +5 -0
  26. package/dist/boilerplates/@batijs/react/files/$.eslintrc.json.js +0 -4
  27. package/dist/boilerplates/@batijs/react/files/$README.md.js +9 -3
  28. package/dist/boilerplates/@batijs/shared/files/package.json +1 -0
  29. package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +15 -0
  30. package/dist/boilerplates/@batijs/shared-server/types/server/vike-handler.d.ts +2 -0
  31. package/dist/boilerplates/@batijs/solid/files/$README.md.js +9 -3
  32. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +12 -0
  33. package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +20 -0
  34. package/dist/boilerplates/@batijs/telefunc/types/server/telefunc-handler.d.ts +2 -0
  35. package/dist/boilerplates/@batijs/vue/files/$README.md.js +9 -3
  36. package/dist/boilerplates/boilerplates.json +35 -0
  37. package/dist/index.js +2 -5
  38. package/package.json +5 -5
@@ -1,17 +1,13 @@
1
1
  // files/$.env.ts
2
- import { appendToEnv, randomBytes } from "@batijs/core";
2
+ import { appendToEnv } from "@batijs/core";
3
3
  async function getEnv(props) {
4
4
  const auth0ClientId = process.env.TEST_AUTH0_CLIENT_ID;
5
+ const auth0ClientSecret = process.env.TEST_AUTH0_CLIENT_SECRET;
5
6
  const auth0BaseUrl = process.env.TEST_AUTH0_ISSUER_BASE_URL;
6
7
  let envContent = await props.readfile?.();
7
- envContent = appendToEnv(
8
- envContent,
9
- "SECRET",
10
- randomBytes(32).toString("hex"),
11
- "Randomly generated by Bati CLI, used by Auth0"
12
- );
13
- envContent = appendToEnv(envContent, "CLIENT_ID", auth0ClientId ?? "", "Auth0 Client ID");
14
- envContent = appendToEnv(envContent, "ISSUER_BASE_URL", auth0BaseUrl ?? "", "Auth0 base URL");
8
+ envContent = appendToEnv(envContent, "AUTH0_CLIENT_ID", auth0ClientId ?? "", "Auth0 Client ID");
9
+ envContent = appendToEnv(envContent, "AUTH0_CLIENT_SECRET", auth0ClientSecret ?? "", "Auth0 Client Secret");
10
+ envContent = appendToEnv(envContent, "AUTH0_ISSUER_BASE_URL", auth0BaseUrl ?? "", "Auth0 base URL");
15
11
  return envContent;
16
12
  }
17
13
  export {
@@ -8,32 +8,23 @@ async function getReadme(props) {
8
8
  - Create Application -> Regular Web Application
9
9
  - What technology are you using for your project? -> Node.js (Express) -> Integrate Now
10
10
  - Configure Auth0:
11
- - Allowed Callback URL: http://localhost:3000/api/auth/callback
11
+ - Allowed Callback URL: http://localhost:3000/api/auth/callback/auth0
12
12
  - Allowed Logout URLs: http://localhost:3000
13
13
  - Save Changes
14
- - Copy your \`clientID\` and \`issuerBaseURL\` and paste it in \`.env\` file like this:
14
+ - Copy your \`Client ID\`, \`Client Secret\` and \`Domain\` and paste it in \`.env\` file like this:
15
15
 
16
16
  \`\`\`env
17
17
  // .env
18
- SECRET=<random string>
19
- CLIENT_ID=<Client ID>
20
- ISSUER_BASE_URL=https://<your-auth0-domain>.<eu>.auth0.com
18
+ AUTH0_CLIENT_SECRET=<Client Secret>
19
+ AUTH0_CLIENT_ID=<Client ID>
20
+ AUTH0_ISSUER_BASE_URL=https://<your-auth0-domain>.<eu>.auth0.com
21
21
  \`\`\`
22
22
 
23
23
  > [!NOTE]
24
- > Environment variables that are automatically made available to Auth0 :
25
- > - \`SECRET\`
26
- > - \`ISSUER_BASE_URL\`
27
- > - \`BASE_URL\`
28
- > - \`CLIENT_ID\`
29
- > - \`CLIENT_SECRET\`
24
+ > Login route is \`http://localhost:3000/api/auth/signin\`.
25
+ > Logout route is \`http://localhost:3000/api/auth/signout\`.
30
26
 
31
- > [!NOTE]
32
- > Login route is \`http://localhost:3000/api/auth/login\`.
33
- > Logout route is \`http://localhost:3000/api/auth/logout\`.
34
-
35
- - Read more [Auth0 Express SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/express)
36
- - Read more [Auth0 Express SDK Quickstarts: Add Login to your Express App](https://auth0.com/docs/quickstart/webapp/express/interactive)
27
+ - Read more [Auth.js: Auth0 provider](https://authjs.dev/reference/core/providers/auth0)
37
28
  `;
38
29
  content.addTodo(todo);
39
30
  return content.finalize();
@@ -0,0 +1,100 @@
1
+ import { Auth, createActionURL, setEnvDefaults, type AuthConfig } from "@auth/core";
2
+ import Auth0 from "@auth/core/providers/auth0";
3
+ import CredentialsProvider from "@auth/core/providers/credentials";
4
+ import type { Session } from "@auth/core/types";
5
+
6
+ const env: Record<string, string | undefined> =
7
+ typeof process?.env !== "undefined"
8
+ ? process.env
9
+ : import.meta && "env" in import.meta
10
+ ? (import.meta as ImportMeta & { env: Record<string, string | undefined> }).env
11
+ : {};
12
+
13
+ if (!globalThis.crypto) {
14
+ /**
15
+ * Polyfill needed if Auth.js code runs on node18
16
+ */
17
+ Object.defineProperty(globalThis, "crypto", {
18
+ value: await import("node:crypto").then((crypto) => crypto.webcrypto as Crypto),
19
+ writable: false,
20
+ configurable: true,
21
+ });
22
+ }
23
+
24
+ const authjsConfig = {
25
+ basePath: "/api/auth",
26
+ trustHost: Boolean(env.AUTH_TRUST_HOST ?? env.VERCEL ?? env.NODE_ENV !== "production"),
27
+ // TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
28
+ secret: "MY_SECRET",
29
+ providers: [
30
+ // TODO: Choose and implement providers
31
+ CredentialsProvider({
32
+ name: "Credentials",
33
+ credentials: {
34
+ username: { label: "Username", type: "text", placeholder: "jsmith" },
35
+ password: { label: "Password", type: "password" },
36
+ },
37
+ async authorize() {
38
+ // Add logic here to look up the user from the credentials supplied
39
+ const user = { id: "1", name: "J Smith", email: "jsmith@example.com" };
40
+
41
+ // Any object returned will be saved in `user` property of the JWT
42
+ // If you return null then an error will be displayed advising the user to check their details.
43
+ // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
44
+ return user ?? null;
45
+ },
46
+ }),
47
+ //# BATI.has("auth0")
48
+ Auth0({
49
+ issuer: env.AUTH0_ISSUER_BASE_URL,
50
+ clientId: env.AUTH0_CLIENT_ID,
51
+ clientSecret: env.AUTH0_CLIENT_SECRET,
52
+ }),
53
+ ],
54
+ } satisfies Omit<AuthConfig, "raw">;
55
+
56
+ /**
57
+ * Retrieve Auth.js session from Request
58
+ */
59
+ export async function getSession(req: Request, config: Omit<AuthConfig, "raw">): Promise<Session | null> {
60
+ setEnvDefaults(process.env, config);
61
+ const requestURL = new URL(req.url);
62
+ const url = createActionURL("session", requestURL.protocol, req.headers, process.env, config.basePath);
63
+
64
+ const response = await Auth(new Request(url, { headers: { cookie: req.headers.get("cookie") ?? "" } }), config);
65
+
66
+ const { status = 200 } = response;
67
+
68
+ const data = await response.json();
69
+
70
+ if (!data || !Object.keys(data).length) return null;
71
+ if (status === 200) return data;
72
+ throw new Error(data.message);
73
+ }
74
+
75
+ /**
76
+ * Add Auth.js session to context
77
+ * @link {@see https://authjs.dev/getting-started/session-management/get-session}
78
+ **/
79
+ export async function authjsSessionMiddleware(
80
+ request: Request,
81
+ context: Record<string | number | symbol, unknown>,
82
+ ): Promise<void> {
83
+ try {
84
+ context.session = await getSession(request, authjsConfig);
85
+ } catch (error) {
86
+ console.debug("authjsSessionMiddleware:", error);
87
+ context.user = null;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Auth.js route
93
+ * @link {@see https://authjs.dev/getting-started/installation}
94
+ **/
95
+ export function authjsHandler<Context extends Record<string | number | symbol, unknown>>(
96
+ request: Request,
97
+ _context?: Context,
98
+ ): Promise<Response> {
99
+ return Auth(request, authjsConfig);
100
+ }
@@ -0,0 +1,16 @@
1
+ import { type AuthConfig } from "@auth/core";
2
+ import type { Session } from "@auth/core/types";
3
+ /**
4
+ * Retrieve Auth.js session from Request
5
+ */
6
+ export declare function getSession(req: Request, config: Omit<AuthConfig, "raw">): Promise<Session | null>;
7
+ /**
8
+ * Add Auth.js session to context
9
+ * @link {@see https://authjs.dev/getting-started/session-management/get-session}
10
+ **/
11
+ export declare function authjsSessionMiddleware(request: Request, context: Record<string | number | symbol, unknown>): Promise<void>;
12
+ /**
13
+ * Auth.js route
14
+ * @link {@see https://authjs.dev/getting-started/installation}
15
+ **/
16
+ export declare function authjsHandler<Context extends Record<string | number | symbol, unknown>>(request: Request, _context?: Context): Promise<Response>;
@@ -1,10 +1,23 @@
1
1
  {
2
2
  "root": true,
3
3
  "parser": "@typescript-eslint/parser",
4
- "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
5
- "plugins": ["@typescript-eslint"],
4
+ "extends": [
5
+ "eslint:recommended",
6
+ "plugin:@typescript-eslint/recommended"
7
+ ],
8
+ "plugins": [
9
+ "@typescript-eslint"
10
+ ],
6
11
  "parserOptions": {
7
12
  "sourceType": "module",
8
13
  "ecmaVersion": "latest"
14
+ },
15
+ "rules": {
16
+ "@typescript-eslint/no-unused-vars": [
17
+ 1,
18
+ {
19
+ "argsIgnorePattern": "^_"
20
+ }
21
+ ]
9
22
  }
10
23
  }
@@ -42,23 +42,24 @@ var require_package = __commonJS({
42
42
  license: "MIT",
43
43
  devDependencies: {
44
44
  "@auth/core": "^0.31.0",
45
+ "@batijs/authjs": "workspace:*",
45
46
  "@batijs/compile": "workspace:*",
46
47
  "@batijs/firebase-auth": "workspace:*",
48
+ "@batijs/shared-server": "workspace:^",
49
+ "@batijs/telefunc": "workspace:*",
47
50
  "@batijs/trpc": "workspace:*",
48
- "@hattip/adapter-node": "^0.0.45",
49
51
  "@trpc/server": "^10.45.2",
50
52
  "@types/cookie-parser": "^1.4.7",
51
53
  "@types/express": "^4.17.21",
52
54
  "@types/node": "^18.19.14",
55
+ "@universal-middleware/express": "^0.0.2",
53
56
  "cookie-parser": "^1.4.6",
54
57
  dotenv: "^16.4.5",
55
58
  express: "^4.19.2",
56
59
  "express-openid-connect": "^2.17.1",
57
- "firebase-admin": "^12.1.1",
58
60
  telefunc: "^0.1.72",
59
61
  tsx: "^4.11.0",
60
62
  vike: "^0.4.172",
61
- "vike-authjs": "^0.1.6",
62
63
  vite: "^5.2.11"
63
64
  },
64
65
  dependencies: {
@@ -111,18 +112,16 @@ async function getPackageJson(props) {
111
112
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
112
113
  devDependencies: [
113
114
  "@types/express",
114
- ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : [],
115
- ...props.meta.BATI.has("auth0") ? ["dotenv"] : []
115
+ ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : []
116
116
  ],
117
117
  dependencies: [
118
- "@hattip/adapter-node",
118
+ "@universal-middleware/express",
119
119
  "express",
120
120
  "tsx",
121
121
  "vite",
122
122
  "vike",
123
- ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
124
- ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : [],
125
- ...props.meta.BATI.has("auth0") ? ["express-openid-connect"] : []
123
+ ...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : [],
124
+ ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
126
125
  ]
127
126
  });
128
127
  }
@@ -2,18 +2,18 @@
2
2
  import "dotenv/config";
3
3
  import { dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
- import CredentialsProvider from "@auth/core/providers/credentials";
6
- import { firebaseAdmin } from "@batijs/firebase-auth/libs/firebaseAdmin";
5
+ import { authjsHandler, authjsSessionMiddleware } from "@batijs/authjs/server/authjs-handler";
6
+ import {
7
+ firebaseAuthLoginHandler,
8
+ firebaseAuthLogoutHandler,
9
+ firebaseAuthMiddleware,
10
+ } from "@batijs/firebase-auth/server/firebase-auth-middleware";
11
+ import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
12
+ import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
7
13
  import { appRouter } from "@batijs/trpc/trpc/server";
8
- import { createMiddleware } from "@hattip/adapter-node";
9
14
  import * as trpcExpress from "@trpc/server/adapters/express";
10
- import cookieParser from "cookie-parser";
11
- import express, { type Request } from "express";
12
- import { auth, type ConfigParams } from "express-openid-connect";
13
- import { getAuth } from "firebase-admin/auth";
14
- import { telefunc } from "telefunc";
15
- import { VikeAuth } from "vike-authjs";
16
- import { renderPage } from "vike/server";
15
+ import { createMiddleware } from "@universal-middleware/express";
16
+ import express from "express";
17
17
 
18
18
  const __filename = fileURLToPath(import.meta.url);
19
19
  const __dirname = dirname(__filename);
@@ -22,6 +22,34 @@ const root = __dirname;
22
22
  const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
23
23
  const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
24
24
 
25
+ interface Middleware<Context extends Record<string | number | symbol, unknown>> {
26
+ (request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
27
+ }
28
+
29
+ export function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
30
+ handler: Middleware<Context>,
31
+ ) {
32
+ return createMiddleware(
33
+ async (context) => {
34
+ const rawRequest = context.platform.request as unknown as Record<string, unknown>;
35
+ rawRequest.context ??= {};
36
+ const response = await handler(context.request, rawRequest.context as Context);
37
+
38
+ if (!response) {
39
+ context.passThrough();
40
+ return new Response("", {
41
+ status: 404,
42
+ });
43
+ }
44
+
45
+ return response;
46
+ },
47
+ {
48
+ alwaysCallNext: false,
49
+ },
50
+ );
51
+ }
52
+
25
53
  startServer();
26
54
 
27
55
  async function startServer() {
@@ -43,104 +71,23 @@ async function startServer() {
43
71
  app.use(viteDevMiddleware);
44
72
  }
45
73
 
46
- if (BATI.has("authjs")) {
74
+ if (BATI.has("authjs") || BATI.has("auth0")) {
47
75
  /**
48
- * AuthJS
49
- *
50
- * TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
51
- * TODO: Choose and implement providers
52
- *
53
- * @link {@see https://authjs.dev/guides/providers/custom-provider}
76
+ * Append Auth.js session to context
54
77
  **/
55
- const Auth = VikeAuth({
56
- secret: "MY_SECRET",
57
- providers: [
58
- CredentialsProvider({
59
- name: "Credentials",
60
- credentials: {
61
- username: { label: "Username", type: "text", placeholder: "jsmith" },
62
- password: { label: "Password", type: "password" },
63
- },
64
- async authorize() {
65
- // Add logic here to look up the user from the credentials supplied
66
- const user = { id: "1", name: "J Smith", email: "jsmith@example.com" };
78
+ app.use(handlerAdapter(authjsSessionMiddleware));
67
79
 
68
- // Any object returned will be saved in `user` property of the JWT
69
- // If you return null then an error will be displayed advising the user to check their details.
70
- // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
71
- return user ?? null;
72
- },
73
- }),
74
- ],
75
- });
76
-
77
- app.all(
78
- "/api/auth/*",
79
- createMiddleware(Auth, {
80
- alwaysCallNext: false,
81
- }),
82
- );
80
+ /**
81
+ * Auth.js route
82
+ * @link {@see https://authjs.dev/getting-started/installation}
83
+ **/
84
+ app.all("/api/auth/*", handlerAdapter(authjsHandler));
83
85
  }
84
86
 
85
87
  if (BATI.has("firebase-auth")) {
86
- app.use(cookieParser());
87
- app.use(async function (req: Request, _, next) {
88
- const sessionCookie: string = req.cookies.__session || "";
89
-
90
- try {
91
- const auth = getAuth(firebaseAdmin);
92
- const decodedIdToken = await auth.verifySessionCookie(sessionCookie, true);
93
- const user = await auth.getUser(decodedIdToken.sub);
94
- req.user = user;
95
- } catch (error) {
96
- console.debug("verifySessionCookie:", error);
97
- req.user = null;
98
- }
99
-
100
- next();
101
- });
102
-
103
- app.use(express.json()); // Parse & make HTTP request body available at `req.body`
104
- app.post("/api/sessionLogin", (req: Request, res) => {
105
- const idToken: string = req.body.idToken || "";
106
-
107
- const expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days
108
-
109
- getAuth(firebaseAdmin)
110
- .createSessionCookie(idToken, { expiresIn })
111
- .then(
112
- (sessionCookie) => {
113
- // Set cookie policy for session cookie.
114
- const options = { maxAge: expiresIn, httpOnly: true, secure: true };
115
- res.cookie("__session", sessionCookie, options);
116
- res.end(JSON.stringify({ status: "success" }));
117
- },
118
- (error) => {
119
- console.error("createSessionCookie:", error);
120
- res.status(401).send("Unauthorized Request");
121
- },
122
- );
123
- });
124
-
125
- app.post("/api/sessionLogout", function (_, res) {
126
- res.clearCookie("__session");
127
- res.end();
128
- });
129
- }
130
-
131
- if (BATI.has("auth0")) {
132
- const config: ConfigParams = {
133
- authRequired: false, // Controls whether authentication is required for all routes
134
- auth0Logout: true, // Uses Auth0 logout feature
135
- baseURL: process.env.BASE_URL?.startsWith("http") ? process.env.BASE_URL : `http://localhost:${port}`, // The URL where the application is served
136
- routes: {
137
- login: "/api/auth/login", // Custom login route, default is : "/login"
138
- logout: "/api/auth/logout", // Custom logout route, default is : "/logout"
139
- callback: "/api/auth/callback", // Custom callback route, default is "/callback"
140
- },
141
- };
142
-
143
- app.use(auth(config));
88
+ app.use(handlerAdapter(firebaseAuthMiddleware));
89
+ app.post("/api/sessionLogin", handlerAdapter(firebaseAuthLoginHandler));
90
+ app.post("/api/sessionLogout", handlerAdapter(firebaseAuthLogoutHandler));
144
91
  }
145
92
 
146
93
  if (BATI.has("trpc")) {
@@ -166,29 +113,7 @@ async function startServer() {
166
113
  *
167
114
  * @link {@see https://telefunc.com}
168
115
  **/
169
- app.post(
170
- "/_telefunc",
171
- createMiddleware(
172
- async (context) => {
173
- const httpResponse = await telefunc({
174
- url: context.request.url.toString(),
175
- method: context.request.method,
176
- body: await context.request.text(),
177
- context,
178
- });
179
- const { body, statusCode, contentType } = httpResponse;
180
- return new Response(body, {
181
- status: statusCode,
182
- headers: {
183
- "content-type": contentType,
184
- },
185
- });
186
- },
187
- {
188
- alwaysCallNext: false,
189
- },
190
- ),
191
- );
116
+ app.post("/_telefunc", handlerAdapter(telefuncHandler));
192
117
  }
193
118
 
194
119
  /**
@@ -196,25 +121,7 @@ async function startServer() {
196
121
  *
197
122
  * @link {@see https://vike.dev}
198
123
  **/
199
- app.all("*", async (req: Request, res, next) => {
200
- const pageContextInit = BATI.has("auth0")
201
- ? { urlOriginal: req.originalUrl, user: req.oidc.user }
202
- : BATI.has("firebase-auth")
203
- ? { urlOriginal: req.originalUrl, user: req.user }
204
- : { urlOriginal: req.originalUrl };
205
-
206
- const pageContext = await renderPage(pageContextInit);
207
- const { httpResponse } = pageContext;
208
-
209
- if (!httpResponse) {
210
- return next();
211
- } else {
212
- const { statusCode, headers } = httpResponse;
213
- headers.forEach(([name, value]) => res.setHeader(name, value));
214
- res.status(statusCode);
215
- httpResponse.pipe(res);
216
- }
217
- });
124
+ app.all("*", handlerAdapter(vikeHandler));
218
125
 
219
126
  app.listen(port, () => {
220
127
  console.log(`Server listening on http://localhost:${port}`);
@@ -1 +1,6 @@
1
1
  import "dotenv/config";
2
+ interface Middleware<Context extends Record<string | number | symbol, unknown>> {
3
+ (request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
4
+ }
5
+ export declare function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(handler: Middleware<Context>): import("@universal-middleware/express/native-fetch").NodeMiddleware;
6
+ export {};
@@ -42,26 +42,23 @@ var require_package = __commonJS({
42
42
  license: "MIT",
43
43
  devDependencies: {
44
44
  "@auth/core": "^0.31.0",
45
+ "@batijs/authjs": "workspace:*",
45
46
  "@batijs/compile": "workspace:*",
46
47
  "@batijs/firebase-auth": "workspace:*",
48
+ "@batijs/shared-server": "workspace:^",
49
+ "@batijs/telefunc": "workspace:^",
47
50
  "@batijs/trpc": "workspace:^",
48
- "@fastify/cookie": "^9.3.1",
49
- "@fastify/formbody": "^7.4.0",
50
51
  "@fastify/middie": "^8.3.1",
51
52
  "@fastify/static": "^7.0.4",
52
- "@hattip/adapter-node": "^0.0.45",
53
53
  "@trpc/server": "^10.45.2",
54
54
  "@types/express": "^4.17.21",
55
55
  "@types/node": "^18.19.14",
56
+ "@universal-middleware/express": "^0.0.2",
56
57
  dotenv: "^16.4.5",
57
- express: "^4.19.2",
58
- "express-openid-connect": "^2.17.1",
59
58
  fastify: "^4.27.0",
60
- "firebase-admin": "^12.1.1",
61
59
  telefunc: "^0.1.72",
62
60
  tsx: "^4.11.0",
63
61
  vike: "^0.4.172",
64
- "vike-authjs": "^0.1.6",
65
62
  vite: "^5.2.11"
66
63
  },
67
64
  dependencies: {
@@ -116,13 +113,12 @@ async function getPackageJson(props) {
116
113
  dependencies: [
117
114
  "@fastify/middie",
118
115
  "@fastify/static",
116
+ "@universal-middleware/express",
119
117
  "fastify",
120
118
  "tsx",
121
119
  "vike",
122
120
  "vite",
123
- ...props.meta.BATI.has("authjs") ? ["@auth/core", "@fastify/formbody", "@hattip/adapter-node", "vike-authjs"] : [],
124
- ...props.meta.BATI.has("firebase-auth") ? ["@fastify/cookie"] : [],
125
- ...props.meta.BATI.has("auth0") ? ["express", "express-openid-connect"] : []
121
+ ...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
126
122
  ]
127
123
  });
128
124
  }