跨域设置
This commit is contained in:
parent
d5f80faedd
commit
367dc4881a
@ -24,6 +24,7 @@
|
|||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"connect-mongo": "^2.0.3",
|
"connect-mongo": "^2.0.3",
|
||||||
"cookie-parser": "^1.4.4",
|
"cookie-parser": "^1.4.4",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"cos-nodejs-sdk-v5": "^2.5.9",
|
"cos-nodejs-sdk-v5": "^2.5.9",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"express-flash": "0.0.2",
|
"express-flash": "0.0.2",
|
||||||
|
@ -8,17 +8,7 @@ import config from '../../../config/config';
|
|||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
// 字体下载
|
|
||||||
// TODO: 待删 字体测试用
|
|
||||||
router.get('/get_font', async (req, res, next) => {
|
|
||||||
const query = req.query;
|
|
||||||
const font_name = query.font_name;
|
|
||||||
const ext = query.ext;
|
|
||||||
const fontPath = path.join(__dirname, `../fonts/${font_name}.${ext}`)
|
|
||||||
console.log(path)
|
|
||||||
|
|
||||||
res.download(fontPath);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,22 @@
|
|||||||
import {Router} from 'express'
|
import {Router} from 'express'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import cors from 'cors'
|
||||||
|
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get('/get_font', async (req, res, next) => {
|
const whitelist = ['https://servicewechat.com']
|
||||||
|
const corsOptions = {
|
||||||
|
origin: function (origin, callback) {
|
||||||
|
if (whitelist.indexOf(origin) !== -1) {
|
||||||
|
callback(null, true)
|
||||||
|
} else {
|
||||||
|
callback(new Error('Not allowed by CORS'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
router.get('/get_font', cors(), async (req, res, next) => {
|
||||||
const query = req.query
|
const query = req.query
|
||||||
const font_name = query.font_name
|
const font_name = query.font_name
|
||||||
const ext = query.ext
|
const ext = query.ext
|
||||||
|
Loading…
x
Reference in New Issue
Block a user