Skip to content

Commit d9cc6bc

Browse files
updated server paths
1 parent cc62496 commit d9cc6bc

7 files changed

Lines changed: 41 additions & 40 deletions

File tree

LiaScript

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
"@fastify/multipart": "^8.1.0",
5555
"@fastify/static": "^7.0.1",
5656
"@liascript/simple-scorm-packager": "^0.3.0",
57-
"@types/fs-extra": "^11.0.4",
58-
"@types/unzipper": "^0.10.11",
5957
"archiver": "^7.0.1",
6058
"epub-gen": "^0.1.0",
6159
"fastify": "^4.26.0",
@@ -64,6 +62,7 @@
6462
"minimist": "^1.2.5",
6563
"node-fetch": "^3.3.2",
6664
"path": "^0.12.7",
65+
"pino-pretty": "^13.0.0",
6766
"puppeteer": "^24.34.0",
6867
"simply-beautiful": "^1.0.1",
6968
"temp": "^0.9.4",
@@ -74,10 +73,11 @@
7473
},
7574
"devDependencies": {
7675
"@parcel/transformer-elm": "^2.16.3",
76+
"@types/fs-extra": "^11.0.4",
7777
"@types/temp": "^0.9.1",
78+
"@types/unzipper": "^0.10.11",
7879
"elm": "^0.19.1-6",
79-
"parcel": "^2.16.3",
80-
"pino-pretty": "^13.0.0"
80+
"parcel": "^2.16.3"
8181
},
8282
"engines": {
8383
"node": ">= 12"

src/export/helper.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ export function tmpDir(): Promise<string> {
3636

3737
/**
3838
* Returns the absolute path to the distribution directory.
39-
* @returns The path to the dist directory
39+
* @returns The path to the dist directory (where index.js is located)
4040
*/
4141
export function dirname(): string {
42-
return path.join(__dirname, DIST_DIR_RELATIVE_PATH)
42+
// Get the directory where the main entry point (index.js) is located
43+
// This works both in Docker and locally because it's relative to the actual running file
44+
const mainFile = require.main?.filename || process.argv[1]
45+
46+
return path.dirname(mainFile)
4347
}
4448

4549
/**
@@ -72,7 +76,7 @@ export function writeFile(filename: string, content: string): Promise<string> {
7276
* @returns A filter function that returns false for hidden folders and node_modules
7377
*/
7478
export function filterHidden(
75-
sourceDir: string
79+
sourceDir: string,
7680
): (src: string, dest: string) => boolean {
7781
return function (src: string, dest: string): boolean {
7882
// Get the relative path of the source folder being copied
@@ -107,7 +111,7 @@ export function filterHidden(
107111
export function injectResponsivevoice(key: string, into: string): string {
108112
return inject(
109113
`<script src="https://code.responsivevoice.org/responsivevoice.js?key=${key}"></script>`,
110-
into
114+
into,
111115
)
112116
}
113117

@@ -120,7 +124,7 @@ export function injectResponsivevoice(key: string, into: string): string {
120124
export function inject(
121125
element: string,
122126
into: string,
123-
head: boolean = false
127+
head: boolean = false,
124128
): string {
125129
return head
126130
? into.replace('<head>', '<head>' + element)
@@ -156,7 +160,7 @@ export async function iframe(
156160
readme: string,
157161
jsonLD: string,
158162
style?: string,
159-
index?: string
163+
index?: string,
160164
): Promise<string> {
161165
await writeFile(
162166
path.join(tmpPath, filename),
@@ -185,7 +189,7 @@ export async function iframe(
185189
186190
</body>
187191
</html>
188-
`)
192+
`),
189193
)
190194

191195
return 'ok'
@@ -200,7 +204,7 @@ export async function iframe(
200204
export async function zip(dir: string, filename: string): Promise<void> {
201205
return new Promise((resolve, reject) => {
202206
const output = fs.createWriteStream(
203-
path.dirname(filename) + '/' + path.basename(filename + '.zip')
207+
path.dirname(filename) + '/' + path.basename(filename + '.zip'),
204208
)
205209

206210
const archive = archiver('zip', {
@@ -212,7 +216,7 @@ export async function zip(dir: string, filename: string): Promise<void> {
212216
output.on('close', function () {
213217
console.log(archive.pointer() + ' total bytes')
214218
console.log(
215-
'archiver has been finalized and the output file descriptor has closed.'
219+
'archiver has been finalized and the output file descriptor has closed.',
216220
)
217221
resolve()
218222
})
@@ -275,7 +279,7 @@ export function getRepository(raw_url: string): {
275279
cmd: string
276280
} | null {
277281
const match = raw_url.match(
278-
/raw\.githubusercontent\.com\/([^\/]+)\/([^\/]+)\/(?:refs\/heads\/)?([^\/]+)\/(.*)/i
282+
/raw\.githubusercontent\.com\/([^\/]+)\/([^\/]+)\/(?:refs\/heads\/)?([^\/]+)\/(.*)/i,
279283
)
280284

281285
if (match?.length === 5) {

src/server/routes/export.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { join, basename } from 'path'
55
import { randomUUID } from 'crypto'
66
import { tmpdir } from 'os'
77
import { fileURLToPath } from 'url'
8-
import { dirname } from 'path'
98
import * as YAML from 'yaml'
109
import { extractZip, findMainMarkdown, isZipFile } from '../utils/zipExtractor'
10+
import { dirname } from '../../export/helper'
1111

1212
export const exportRouter: FastifyPluginAsync = async (fastify) => {
1313
// GET /api/presets - Get available presets configuration
@@ -16,16 +16,9 @@ export const exportRouter: FastifyPluginAsync = async (fastify) => {
1616
// Find presets.yaml relative to the dist directory
1717
// When bundled by Parcel, __dirname points to the src directory
1818
// We need to go up and find the dist/server directory
19-
const distServerPath = join(__dirname, '..', '..', 'dist', 'server')
19+
const distServerPath = join(dirname(), 'server')
2020
let presetsPath = join(distServerPath, 'presets.yaml')
2121

22-
// Fallback: try relative to the current working directory
23-
try {
24-
await readFile(presetsPath, 'utf-8')
25-
} catch {
26-
presetsPath = join(process.cwd(), 'dist', 'server', 'presets.yaml')
27-
}
28-
2922
const presetsContent = await readFile(presetsPath, 'utf-8')
3023
const presets = YAML.parse(presetsContent)
3124
return { presets: presets.presets }

src/server/server.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { join, dirname } from 'path'
55
import { fileURLToPath } from 'url'
66
import { exportRouter } from './routes/export'
77
import { JobQueue } from './queue/jobQueue'
8+
import { existsSync } from 'fs'
89

910
export const jobQueue = new JobQueue()
1011

@@ -32,7 +33,20 @@ export async function startServer(port: number = 3000): Promise<void> {
3233
// Serve static files (HTML, CSS, JS)
3334
// In development, public is in src/server/public
3435
// In production (built), it will be in dist/server/public
35-
const publicDir = join(__dirname, 'public')
36+
// In Docker/production, public is in liascript-exporter/server/public
37+
// In development, fallback to src/server/public
38+
const distPublicDir = join(
39+
process.cwd(),
40+
'liascript-exporter',
41+
'server',
42+
'public',
43+
)
44+
const fallbackPublicDir = join(__dirname, 'public')
45+
const publicDir = existsSync(distPublicDir)
46+
? distPublicDir
47+
: fallbackPublicDir
48+
49+
console.log('Serving static files from:', publicDir)
3650

3751
await fastify.register(fastifyStatic, {
3852
root: publicDir,

0 commit comments

Comments
 (0)