fix(magic): bundle mobileconfig template via Nitro serverAssets
Previously read template via process.cwd() + 'ops/mdm/…' — but pm2
runs the bundled output from /root, not the repo root, so the path
resolved to /root/ops/mdm/… (does not exist) → HTTP 500 'Profile
template not found' after Mac registration.
Switch to Nitro's serverAssets (baseName 'mdm', dir '../ops/mdm')
which is bundled at build-time and read via
useStorage('assets:server'). cwd-independent + survives any deploy
layout change.
This commit is contained in:
parent
038c383bef
commit
d212452a5d
@ -10,6 +10,10 @@ export default defineNitroConfig({
|
|||||||
// Default-publicAssets greift nicht zuverlässig wenn srcDir auf "server" zeigt.
|
// Default-publicAssets greift nicht zuverlässig wenn srcDir auf "server" zeigt.
|
||||||
publicAssets: [{ baseURL: "/", dir: "../public", maxAge: 60 * 60 }],
|
publicAssets: [{ baseURL: "/", dir: "../public", maxAge: 60 * 60 }],
|
||||||
|
|
||||||
|
// Server-Assets: zur Build-Time eingebundelte Files (mobileconfig-Template etc.).
|
||||||
|
// Lesbar via useStorage('assets:server').getItem('mdm/<file>').
|
||||||
|
serverAssets: [{ baseName: "mdm", dir: "../ops/mdm" }],
|
||||||
|
|
||||||
// Supabase als external dep — nicht bundlen
|
// Supabase als external dep — nicht bundlen
|
||||||
externals: {
|
externals: {
|
||||||
inline: [/^(?!@supabase\/supabase-js)/],
|
inline: [/^(?!@supabase\/supabase-js)/],
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import { randomUUID } from "crypto";
|
import { randomUUID } from "crypto";
|
||||||
import { readFile } from "fs/promises";
|
|
||||||
import { resolve } from "path";
|
|
||||||
import { findMagicDeviceByToken } from "../../db/devices";
|
import { findMagicDeviceByToken } from "../../db/devices";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/magic/profile.mobileconfig?token=<dnsToken>
|
* GET /api/magic/profile.mobileconfig?token=<dnsToken>
|
||||||
*
|
*
|
||||||
* Generiert personalisiertes DNS-Configuration-Profile für macOS.
|
* Generiert personalisiertes DNS-Configuration-Profile für macOS.
|
||||||
* Template: ops/mdm/rebreak-mac-dns-filter.mobileconfig
|
* Template: ops/mdm/rebreak-mac-dns-filter.mobileconfig (via Nitro serverAssets
|
||||||
|
* unter baseName "mdm" eingebundelt — siehe nitro.config.ts).
|
||||||
*
|
*
|
||||||
* Ersetzt:
|
* Ersetzt:
|
||||||
* - ServerURL: /dns-query → /dns-query/{token}
|
* - ServerURL: /dns-query → /dns-query/{token}
|
||||||
@ -36,16 +35,16 @@ export default defineEventHandler(async (event) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template lesen
|
// Template via Nitro serverAssets lesen (build-time eingebundelt → cwd-unabhängig).
|
||||||
const templatePath = resolve(
|
const storage = useStorage("assets:server");
|
||||||
process.cwd(),
|
const template = (await storage.getItem(
|
||||||
"ops/mdm/rebreak-mac-dns-filter.mobileconfig",
|
"mdm/rebreak-mac-dns-filter.mobileconfig",
|
||||||
);
|
)) as string | null;
|
||||||
let template: string;
|
|
||||||
try {
|
if (!template) {
|
||||||
template = await readFile(templatePath, "utf-8");
|
console.error(
|
||||||
} catch (err: any) {
|
"[Magic] Profile template missing in serverAssets (mdm/rebreak-mac-dns-filter.mobileconfig)",
|
||||||
console.error("[Magic] Failed to read profile template:", err);
|
);
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
message: "Profile template not found",
|
message: "Profile template not found",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user