mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-24 15:07:31 -05:00
fix: add __appRoot to fix bundler messing up __dirname for nested files
This commit is contained in:
parent
fec123d838
commit
d56b9498ea
4
src/app-root.ts
Normal file
4
src/app-root.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// ! Do not move this file, it must be in the root of the project for __dirname to resolve correctly
|
||||
// * Node.js does not have a built-in way to get the root directory of the project, so we need to set it manually
|
||||
// * When using a bundler, __dirname will not work as expected in nested files so we need a consistent way to get the root directory
|
||||
export const __appRoot = __dirname;
|
||||
|
|
@ -2,12 +2,13 @@ import path from 'node:path';
|
|||
import express from 'express';
|
||||
import subdomain from 'express-subdomain';
|
||||
import { fileErrCallback } from '@/util';
|
||||
import { __appRoot } from '@/app-root';
|
||||
|
||||
const npdi = express.Router();
|
||||
|
||||
npdi.get('/p01/data/1/:titleHash/:dataID/:fileHash', (request, response) => {
|
||||
const { titleHash, fileHash } = request.params;
|
||||
const contentPath = path.normalize(`${__dirname}/../../cdn/content/encrypted/${titleHash}/${fileHash}`);
|
||||
const contentPath = path.normalize(`${__appRoot}../cdn/content/encrypted/${titleHash}/${fileHash}`);
|
||||
|
||||
response.sendFile(contentPath, {
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ import path from 'node:path';
|
|||
import express from 'express';
|
||||
import subdomain from 'express-subdomain';
|
||||
import { fileErrCallback } from '@/util';
|
||||
import { __appRoot } from '@/app-root';
|
||||
|
||||
const npts = express.Router();
|
||||
|
||||
npts.get('/p01/tasksheet/:id/:hash/:fileName', (request, response) => {
|
||||
const { id, hash, fileName } = request.params;
|
||||
const tasksheetPath = path.normalize(`${__dirname}/../../cdn/tasksheet/${id}/${hash}/${fileName}`);
|
||||
const tasksheetPath = path.normalize(`${__appRoot}/../cdn/tasksheet/${id}/${hash}/${fileName}`);
|
||||
|
||||
response.sendFile(tasksheetPath, {
|
||||
headers: {
|
||||
|
|
@ -18,7 +19,7 @@ npts.get('/p01/tasksheet/:id/:hash/:fileName', (request, response) => {
|
|||
|
||||
npts.get('/p01/tasksheet/:id/:hash/:subfolder/:fileName', (request, response) => {
|
||||
const { id, hash, subfolder, fileName } = request.params;
|
||||
const tasksheetPath = path.normalize(`${__dirname}/../../cdn/tasksheet/${id}/${hash}/_subfolder/${subfolder}/${fileName}`);
|
||||
const tasksheetPath = path.normalize(`${__appRoot}/../cdn/tasksheet/${id}/${hash}/_subfolder/${subfolder}/${fileName}`);
|
||||
|
||||
response.sendFile(tasksheetPath, {
|
||||
headers: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user