@alstar/studio 0.0.0-beta.13 → 0.0.0-beta.15
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/api/auth.ts +11 -14
- package/bin/build-ssg.ts +42 -0
- package/index.ts +9 -3
- package/package.json +5 -2
- package/types.ts +1 -0
package/api/auth.ts
CHANGED
|
@@ -9,24 +9,21 @@ import { setCookie } from 'hono/cookie'
|
|
|
9
9
|
const app = new Hono<{ Bindings: HttpBindings }>()
|
|
10
10
|
|
|
11
11
|
app.post('/register', async (c) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const data = Object.fromEntries(formData.entries())
|
|
15
|
-
|
|
16
|
-
if (!data || !data.email || !data.password) return
|
|
12
|
+
const formData = await c.req.formData()
|
|
13
|
+
const data = Object.fromEntries(formData.entries())
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
if (!data || !data.email || !data.password) return
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
email: data.email?.toString(),
|
|
22
|
-
hash: hash,
|
|
23
|
-
})
|
|
17
|
+
const hash = createHash(data.password.toString())
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
19
|
+
db.insertInto('users', {
|
|
20
|
+
email: data.email?.toString(),
|
|
21
|
+
hash: hash,
|
|
29
22
|
})
|
|
23
|
+
|
|
24
|
+
setCookie(c, 'login', 'yes')
|
|
25
|
+
|
|
26
|
+
return c.redirect('/studio')
|
|
30
27
|
})
|
|
31
28
|
|
|
32
29
|
app.post('/login', async (c) => {
|
package/bin/build-ssg.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { type SSGPlugin, toSSG } from 'hono/ssg'
|
|
4
|
+
import fs from 'fs/promises'
|
|
5
|
+
|
|
6
|
+
const root = path.resolve('.')
|
|
7
|
+
|
|
8
|
+
let app
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
app = (await import(path.join(root, 'index.ts'))).default
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.log(error)
|
|
14
|
+
console.log('Found no app')
|
|
15
|
+
console.log('Main app needs to be the default export in ./index.ts')
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await existingStaticFolder()
|
|
20
|
+
|
|
21
|
+
const excludeStudioPlugin: SSGPlugin = {
|
|
22
|
+
beforeRequestHook: (req) => {
|
|
23
|
+
if (!req.url.includes('/studio/')) {
|
|
24
|
+
return req
|
|
25
|
+
}
|
|
26
|
+
return false
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
await toSSG(app, fs, { plugins: [excludeStudioPlugin] })
|
|
31
|
+
|
|
32
|
+
await fs.cp(path.join(root, 'public'), path.join(root, 'static'), {
|
|
33
|
+
recursive: true,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
console.log('🚀 Done generating static build')
|
|
37
|
+
|
|
38
|
+
process.exit(0)
|
|
39
|
+
|
|
40
|
+
async function existingStaticFolder() {
|
|
41
|
+
return fs.rm(path.join(root, 'static'), { recursive: true }).catch(() => {})
|
|
42
|
+
}
|
package/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { getConfig } from './utils/get-config.ts'
|
|
|
14
14
|
import startupLog from './utils/startup-log.ts'
|
|
15
15
|
import { apiRoutes } from './api/index.ts'
|
|
16
16
|
import { mcpRoutes } from './api/mcp.ts'
|
|
17
|
+
import packageJSON from './package.json' with { type: 'json' }
|
|
17
18
|
|
|
18
19
|
import auth from './utils/auth.ts'
|
|
19
20
|
import ErrorPage from './pages/error.ts'
|
|
@@ -25,6 +26,7 @@ export let rootdir = './node_modules/@alstar/studio'
|
|
|
25
26
|
export let studioStructure: types.Structure = {}
|
|
26
27
|
export let studioConfig: types.StudioConfig = {
|
|
27
28
|
siteName: '',
|
|
29
|
+
fileBasedRouter: true,
|
|
28
30
|
port: 3000,
|
|
29
31
|
structure: {},
|
|
30
32
|
}
|
|
@@ -72,8 +74,10 @@ const createStudio = async (config: types.StudioConfig) => {
|
|
|
72
74
|
/**
|
|
73
75
|
* User pages
|
|
74
76
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (studioConfig.fileBasedRouter) {
|
|
78
|
+
const pages = await fileBasedRouter('./pages')
|
|
79
|
+
if (pages) app.route('/', pages)
|
|
80
|
+
}
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* Error pages
|
|
@@ -95,7 +99,8 @@ const createStudio = async (config: types.StudioConfig) => {
|
|
|
95
99
|
'/studio/backups/*',
|
|
96
100
|
serveStatic({
|
|
97
101
|
root: './',
|
|
98
|
-
rewriteRequestPath: (path) =>
|
|
102
|
+
rewriteRequestPath: (path) =>
|
|
103
|
+
path.replace(/^\/studio\/backups/, '/backups'),
|
|
99
104
|
}),
|
|
100
105
|
)
|
|
101
106
|
|
|
@@ -141,3 +146,4 @@ export { type RequestContext } from './types.ts'
|
|
|
141
146
|
export { createStudio }
|
|
142
147
|
export { html, type HtmlEscapedString } from './utils/html.ts'
|
|
143
148
|
export { query } from './queries/index.ts'
|
|
149
|
+
export const version = packageJSON.version
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alstar/studio",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
|
+
"bin": {
|
|
7
|
+
"alstar": "./bin/build-ssg.ts"
|
|
8
|
+
},
|
|
6
9
|
"engines": {
|
|
7
10
|
"node": ">=23.8"
|
|
8
11
|
},
|
|
@@ -10,8 +13,8 @@
|
|
|
10
13
|
"@hono/node-server": "^1.18.1",
|
|
11
14
|
"@starfederation/datastar-sdk": "1.0.0-RC.1",
|
|
12
15
|
"hono": "^4.8.12",
|
|
16
|
+
"@alstar/ui": "0.0.0-beta.2",
|
|
13
17
|
"@alstar/refresher": "0.0.0-beta.3",
|
|
14
|
-
"@alstar/ui": "0.0.0-beta.1",
|
|
15
18
|
"@alstar/db": "0.0.0-beta.1"
|
|
16
19
|
},
|
|
17
20
|
"devDependencies": {
|