add cors
This commit is contained in:
parent
46b8d91c1e
commit
62409d6bcf
1 changed files with 14 additions and 1 deletions
15
index.js
15
index.js
|
@ -5,6 +5,7 @@ const fileUpload = require('express-fileupload');
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const mime = require('mime-types')
|
||||
const cors = require('cors');
|
||||
|
||||
const app = express();
|
||||
|
||||
|
@ -61,10 +62,22 @@ const getFileType = (filename) => {
|
|||
return type;
|
||||
};
|
||||
|
||||
const allowlist = ['https://files.hippoz.xyz', 'https://hippoz.xyz']
|
||||
const corsOptions = {
|
||||
origin: function (origin, callback) {
|
||||
if (whitelist.indexOf(origin) !== -1) {
|
||||
callback(null, true)
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.use('*', cors(corsOptions));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.render('upload');
|
||||
// res.render('upload');
|
||||
res.redirect(config.url);
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue