mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-12-09 14:40:27 +08:00
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.proxyPlugin = void 0;
|
|
const url_1 = require("url");
|
|
exports.proxyPlugin = ({ app, config, server }) => {
|
|
if (!config.proxy) {
|
|
return;
|
|
}
|
|
const debug = require('debug')('vite:proxy');
|
|
const proxy = require('koa-proxies');
|
|
const options = config.proxy;
|
|
Object.keys(options).forEach((path) => {
|
|
let opts = options[path];
|
|
if (typeof opts === 'string') {
|
|
opts = { target: opts };
|
|
}
|
|
opts.logs = (ctx, target) => {
|
|
debug(`${ctx.req.method} ${ctx.req.oldPath} proxy to -> ${new url_1.URL(ctx.req.url, target)}`);
|
|
};
|
|
app.use(proxy(path, opts));
|
|
});
|
|
server.on('upgrade', (req, socket, head) => {
|
|
if (req.headers['sec-websocket-protocol'] !== 'vite-hmr') {
|
|
for (const path in options) {
|
|
let opts = options[path];
|
|
if (typeof opts === 'object' && opts.ws) {
|
|
proxy.proxy.ws(req, socket, head, opts);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//# sourceMappingURL=serverPluginProxy.js.map
|