create-authhero 0.37.0 → 0.38.0
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/dist/local/src/index.ts +3 -65
- package/package.json +1 -1
package/dist/local/src/index.ts
CHANGED
|
@@ -4,62 +4,6 @@ import { Kysely } from "kysely";
|
|
|
4
4
|
import Database from "better-sqlite3";
|
|
5
5
|
import createAdapters from "@authhero/kysely-adapter";
|
|
6
6
|
import createApp from "./app";
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import { execSync } from "child_process";
|
|
10
|
-
import https from "https";
|
|
11
|
-
|
|
12
|
-
// Generate self-signed certificates for local HTTPS if they don't exist
|
|
13
|
-
const certDir = path.join(process.cwd(), ".certs");
|
|
14
|
-
const keyPath = path.join(certDir, "localhost-key.pem");
|
|
15
|
-
const certPath = path.join(certDir, "localhost.pem");
|
|
16
|
-
|
|
17
|
-
function ensureCertificates() {
|
|
18
|
-
if (!fs.existsSync(certDir)) {
|
|
19
|
-
fs.mkdirSync(certDir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) {
|
|
23
|
-
console.log("🔑 Generating self-signed certificates for local HTTPS...");
|
|
24
|
-
|
|
25
|
-
// Try mkcert first (if installed), otherwise fall back to openssl
|
|
26
|
-
try {
|
|
27
|
-
execSync(`which mkcert`, { stdio: "ignore" });
|
|
28
|
-
execSync(
|
|
29
|
-
`mkcert -key-file ${keyPath} -cert-file ${certPath} localhost 127.0.0.1`,
|
|
30
|
-
{
|
|
31
|
-
stdio: "inherit",
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
console.log("✅ Certificates generated with mkcert");
|
|
35
|
-
} catch {
|
|
36
|
-
// Fall back to openssl
|
|
37
|
-
try {
|
|
38
|
-
execSync(
|
|
39
|
-
`openssl req -x509 -newkey rsa:2048 -keyout "${keyPath}" -out "${certPath}" -days 365 -nodes -subj "/CN=localhost"`,
|
|
40
|
-
{ stdio: "inherit" },
|
|
41
|
-
);
|
|
42
|
-
console.log("✅ Self-signed certificates generated with openssl");
|
|
43
|
-
console.log(
|
|
44
|
-
"⚠️ You may need to trust the certificate in your browser",
|
|
45
|
-
);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.error(
|
|
48
|
-
"❌ Failed to generate certificates. Please install mkcert or openssl",
|
|
49
|
-
);
|
|
50
|
-
console.error(
|
|
51
|
-
" Install mkcert: brew install mkcert && mkcert -install",
|
|
52
|
-
);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
key: fs.readFileSync(keyPath),
|
|
60
|
-
cert: fs.readFileSync(certPath),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
7
|
|
|
64
8
|
// Initialize SQLite database
|
|
65
9
|
let db: Kysely<any>;
|
|
@@ -90,19 +34,15 @@ const app = createApp({
|
|
|
90
34
|
"https://manage.authhero.net",
|
|
91
35
|
"https://local.authhero.net",
|
|
92
36
|
"http://localhost:5173",
|
|
93
|
-
"https://localhost:5173",
|
|
94
37
|
],
|
|
95
38
|
});
|
|
96
39
|
|
|
97
40
|
// Start the server
|
|
98
41
|
const port = Number(process.env.PORT) || 3000;
|
|
99
|
-
const issuer = process.env.ISSUER || `
|
|
100
|
-
|
|
101
|
-
// Get or generate certificates
|
|
102
|
-
const { key, cert } = ensureCertificates();
|
|
42
|
+
const issuer = process.env.ISSUER || `http://localhost:${port}/`;
|
|
103
43
|
|
|
104
|
-
console.log(`🔐 AuthHero server running at
|
|
105
|
-
console.log(`📚 API documentation available at
|
|
44
|
+
console.log(`🔐 AuthHero server running at http://localhost:${port}`);
|
|
45
|
+
console.log(`📚 API documentation available at http://localhost:${port}/docs`);
|
|
106
46
|
console.log(`🌐 Portal available at https://local.authhero.net`);
|
|
107
47
|
|
|
108
48
|
serve({
|
|
@@ -113,6 +53,4 @@ serve({
|
|
|
113
53
|
});
|
|
114
54
|
},
|
|
115
55
|
port,
|
|
116
|
-
createServer: https.createServer,
|
|
117
|
-
serverOptions: { key, cert },
|
|
118
56
|
});
|