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.
|
||||
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
|
||||
externals: {
|
||||
inline: [/^(?!@supabase\/supabase-js)/],
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import { randomUUID } from "crypto";
|
||||
import { readFile } from "fs/promises";
|
||||
import { resolve } from "path";
|
||||
import { findMagicDeviceByToken } from "../../db/devices";
|
||||
|
||||
/**
|
||||
* GET /api/magic/profile.mobileconfig?token=<dnsToken>
|
||||
*
|
||||
* 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:
|
||||
* - ServerURL: /dns-query → /dns-query/{token}
|
||||
@ -36,16 +35,16 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Template lesen
|
||||
const templatePath = resolve(
|
||||
process.cwd(),
|
||||
"ops/mdm/rebreak-mac-dns-filter.mobileconfig",
|
||||
// Template via Nitro serverAssets lesen (build-time eingebundelt → cwd-unabhängig).
|
||||
const storage = useStorage("assets:server");
|
||||
const template = (await storage.getItem(
|
||||
"mdm/rebreak-mac-dns-filter.mobileconfig",
|
||||
)) as string | null;
|
||||
|
||||
if (!template) {
|
||||
console.error(
|
||||
"[Magic] Profile template missing in serverAssets (mdm/rebreak-mac-dns-filter.mobileconfig)",
|
||||
);
|
||||
let template: string;
|
||||
try {
|
||||
template = await readFile(templatePath, "utf-8");
|
||||
} catch (err: any) {
|
||||
console.error("[Magic] Failed to read profile template:", err);
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: "Profile template not found",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user