跨域设置

This commit is contained in:
yulixing 2019-06-25 19:38:40 +08:00
parent d5f80faedd
commit 367dc4881a
3 changed files with 15 additions and 11 deletions

View File

@ -24,6 +24,7 @@
"compression": "^1.7.4",
"connect-mongo": "^2.0.3",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"cos-nodejs-sdk-v5": "^2.5.9",
"express": "^4.16.4",
"express-flash": "0.0.2",

View File

@ -8,17 +8,7 @@ import config from '../../../config/config';
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);
});

View File

@ -1,9 +1,22 @@
import {Router} from 'express'
import path from 'path'
import cors from 'cors'
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 font_name = query.font_name
const ext = query.ext