-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupProxy.js
More file actions
30 lines (24 loc) · 891 Bytes
/
setupProxy.js
File metadata and controls
30 lines (24 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from 'fs';
import path from 'path';
import { Proxy } from '@domoinc/ryuu-proxy';
import manifestJson from './public/manifest.json';
export function setupRyuuProxy(server) {
let manifest = manifestJson;
const tempPath = path.join(process.cwd(), '.tmp', 'manifest.json');
try {
const tempManifestContent = fs.readFileSync(tempPath, 'utf-8');
manifest = JSON.parse(tempManifestContent);
} catch {
// Using default manifest when temp manifest is not available
}
const config = { manifest };
const proxy = new Proxy(config);
proxy.onError = (error, response) => {
const status = error.response?.data?.statusCode || 500;
const message = error.response?.data?.statusMessage || error.message || 'Proxy error';
response.statusCode = status;
response.end(message);
};
// Apply the middleware
server.middlewares.use(proxy.express());
}