|
1 | 1 | import express from 'express' |
2 | 2 | import multer from 'multer' |
3 | | -import path from 'path' |
4 | | -import fs from 'fs' |
5 | | -import { fileURLToPath } from 'url' |
6 | | -import { dirname } from 'path' |
| 3 | +import path from 'node:path' |
| 4 | +import fs from 'node:fs' |
| 5 | +import { fileURLToPath } from 'node:url' |
| 6 | +import { dirname } from 'node:path' |
7 | 7 | import { createProxyMiddleware } from 'http-proxy-middleware' |
8 | 8 | import { |
9 | 9 | dcloud, |
@@ -92,13 +92,18 @@ export function createServer(port = 8800) { |
92 | 92 | res.redirect('/md/') |
93 | 93 | }) |
94 | 94 |
|
95 | | - console.log('代理到: https://md.doocs.workers.dev') |
96 | | - app.use(createProxyMiddleware({ |
97 | | - target: 'https://md.doocs.workers.dev', |
| 95 | + console.log('代理到: https://md.doocs.org/') |
| 96 | + app.use('/md/', createProxyMiddleware({ |
| 97 | + target: 'https://md.doocs.org/', |
98 | 98 | changeOrigin: true, |
99 | | - onError: (err, req, res) => { |
100 | | - console.error(`代理错误 ${req.path}:`, err.message) |
101 | | - res.status(502).send('代理服务暂不可用,请检查网络连接') |
| 99 | + pathRewrite: { |
| 100 | + '^/md/': '', |
| 101 | + }, |
| 102 | + on: { |
| 103 | + error: (err, req, res) => { |
| 104 | + console.error(`代理错误 ${req.path}:`, err) |
| 105 | + res.status(502).send(`代理服务暂不可用,请检查网络连接 ${err.message}`) |
| 106 | + }, |
102 | 107 | }, |
103 | 108 | })) |
104 | 109 |
|
|
0 commit comments