@rip-lang/server 1.4.1 → 1.4.2
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/browse.rip +7 -9
- package/package.json +2 -2
- package/serving/static.rip +14 -6
package/browse.rip
CHANGED
|
@@ -5,22 +5,19 @@
|
|
|
5
5
|
# Built-in file browser when no index.rip or index.ts exists in the target
|
|
6
6
|
# directory. Activated automatically by `rip server` when no app entry is found.
|
|
7
7
|
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
8
|
+
# Default mode is run: HTML renders, images display.
|
|
9
|
+
# Text files that can't run are shown with syntax highlighting.
|
|
10
10
|
# ==============================================================================
|
|
11
11
|
|
|
12
12
|
import { use, start, notFound } from '@rip-lang/server'
|
|
13
|
-
import { serve } from '@rip-lang/server/middleware'
|
|
14
13
|
import { statSync } from 'node:fs'
|
|
15
14
|
import { join, resolve, basename } from 'node:path'
|
|
16
|
-
import { renderDirectoryListing, renderMarkdown, renderTextFile, isTextFile, serveRipHighlightGrammar } from './serving/static.rip'
|
|
15
|
+
import { renderDirectoryListing, renderMarkdown, renderTextFile, isTextFile, serveRipHighlightGrammar, findIndexFile } from './serving/static.rip'
|
|
17
16
|
|
|
18
17
|
root = resolve(process.env.APP_BASE_DIR or process.cwd())
|
|
19
18
|
rootSlash = root + '/'
|
|
20
19
|
rootName = basename(root) or root
|
|
21
20
|
|
|
22
|
-
use serve dir: root, bundle: [], watch: true
|
|
23
|
-
|
|
24
21
|
notFound ->
|
|
25
22
|
if @req.path is '/_rip/hljs-rip.js'
|
|
26
23
|
res = serveRipHighlightGrammar()
|
|
@@ -44,7 +41,8 @@ notFound ->
|
|
|
44
41
|
try
|
|
45
42
|
html = renderMarkdown(path)
|
|
46
43
|
return new Response html, { headers: { 'Content-Type': 'text/html; charset=UTF-8' } }
|
|
47
|
-
|
|
44
|
+
# Text files that can't "run" get syntax highlighted
|
|
45
|
+
if isTextFile(path) and not path.endsWith('.html') and not path.endsWith('.htm') and not path.endsWith('.rip')
|
|
48
46
|
try
|
|
49
47
|
html = renderTextFile(path)
|
|
50
48
|
return new Response html, { headers: { 'Content-Type': 'text/html; charset=UTF-8' } }
|
|
@@ -52,8 +50,8 @@ notFound ->
|
|
|
52
50
|
|
|
53
51
|
if stat.isDirectory()
|
|
54
52
|
return new Response(null, { status: 301, headers: { Location: "#{reqPath}/" } }) unless reqPath.endsWith('/')
|
|
55
|
-
indexPath =
|
|
56
|
-
if
|
|
53
|
+
indexPath = findIndexFile(path)
|
|
54
|
+
if indexPath
|
|
57
55
|
return @send indexPath, 'text/html; charset=UTF-8'
|
|
58
56
|
return new Response renderDirectoryListing(reqPath, path, rootName), { headers: { 'Content-Type': 'text/html; charset=UTF-8' } }
|
|
59
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Bun-native content server: static sites, apps, HTTP proxy, and TCP/TLS passthrough",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "api.rip",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"rip-lang": ">=3.13.
|
|
50
|
+
"rip-lang": ">=3.13.133"
|
|
51
51
|
},
|
|
52
52
|
"files": [
|
|
53
53
|
"api.rip",
|
package/serving/static.rip
CHANGED
|
@@ -321,6 +321,16 @@ export renderTextFile = (filePath) ->
|
|
|
321
321
|
|
|
322
322
|
# --- Static file serving ---
|
|
323
323
|
|
|
324
|
+
INDEX_FILES = ['index.html', 'index.rip', 'index.ts', 'index.tsx', 'index.jsx', 'index.js']
|
|
325
|
+
|
|
326
|
+
export findIndexFile = (dir) ->
|
|
327
|
+
for name in INDEX_FILES
|
|
328
|
+
p = join(dir, name)
|
|
329
|
+
try
|
|
330
|
+
if statSync(p).isFile()
|
|
331
|
+
return p
|
|
332
|
+
null
|
|
333
|
+
|
|
324
334
|
export serveRipHighlightGrammar = ->
|
|
325
335
|
return null unless HLJS_RIP_PATH
|
|
326
336
|
content = readFileSync(HLJS_RIP_PATH, 'utf8')
|
|
@@ -356,12 +366,10 @@ export serveStaticRoute = (req, url, route) ->
|
|
|
356
366
|
if stat.isDirectory()
|
|
357
367
|
unless pathname.endsWith('/')
|
|
358
368
|
return Response.redirect("#{pathname}/", 301)
|
|
359
|
-
indexPath =
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
file = Bun.file(indexPath)
|
|
364
|
-
return new Response(file, { headers: { 'content-type': 'text/html; charset=UTF-8' } })
|
|
369
|
+
indexPath = findIndexFile(filePath)
|
|
370
|
+
if indexPath
|
|
371
|
+
file = Bun.file(indexPath)
|
|
372
|
+
return new Response(file, { headers: { 'content-type': 'text/html; charset=UTF-8' } })
|
|
365
373
|
if route.browse and acceptsHtml(req)
|
|
366
374
|
rootName = basename(staticDir)
|
|
367
375
|
html = renderDirectoryListing(pathname, filePath, rootName)
|