mirror of https://github.com/Chocobozzz/PeerTube
move CORS allowance to the REST API router
parent
b229e38d50
commit
12daa83784
32
server.ts
32
server.ts
|
@ -84,22 +84,24 @@ import { UpdateVideosScheduler } from './server/lib/schedulers/update-videos-sch
|
||||||
|
|
||||||
// ----------- App -----------
|
// ----------- App -----------
|
||||||
|
|
||||||
// Enable CORS
|
// Enable CORS for develop
|
||||||
app.use((req, res, next) => {
|
if (isTestInstance()) {
|
||||||
// These routes have already cors
|
app.use((req, res, next) => {
|
||||||
if (
|
// These routes have already cors
|
||||||
req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 &&
|
if (
|
||||||
req.path.indexOf(STATIC_PATHS.WEBSEED) === -1
|
req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 &&
|
||||||
) {
|
req.path.indexOf(STATIC_PATHS.WEBSEED) === -1
|
||||||
return (cors({
|
) {
|
||||||
origin: '*',
|
return (cors({
|
||||||
exposedHeaders: 'Retry-After',
|
origin: '*',
|
||||||
credentials: true
|
exposedHeaders: 'Retry-After',
|
||||||
}))(req, res, next)
|
credentials: true
|
||||||
}
|
}))(req, res, next)
|
||||||
|
}
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// For the logger
|
// For the logger
|
||||||
app.use(morgan('combined', {
|
app.use(morgan('combined', {
|
||||||
|
|
|
@ -8,9 +8,16 @@ import { accountsRouter } from './accounts'
|
||||||
import { videosRouter } from './videos'
|
import { videosRouter } from './videos'
|
||||||
import { badRequest } from '../../helpers/express-utils'
|
import { badRequest } from '../../helpers/express-utils'
|
||||||
import { videoChannelRouter } from './video-channel'
|
import { videoChannelRouter } from './video-channel'
|
||||||
|
import * as cors from 'cors'
|
||||||
|
|
||||||
const apiRouter = express.Router()
|
const apiRouter = express.Router()
|
||||||
|
|
||||||
|
apiRouter.use(cors({
|
||||||
|
origin: '*',
|
||||||
|
exposedHeaders: 'Retry-After',
|
||||||
|
credentials: true
|
||||||
|
}))
|
||||||
|
|
||||||
apiRouter.use('/server', serverRouter)
|
apiRouter.use('/server', serverRouter)
|
||||||
apiRouter.use('/oauth-clients', oauthClientsRouter)
|
apiRouter.use('/oauth-clients', oauthClientsRouter)
|
||||||
apiRouter.use('/config', configRouter)
|
apiRouter.use('/config', configRouter)
|
||||||
|
|
Loading…
Reference in New Issue