Skip to content
Permalink
Browse files
fixed cors issue
  • Loading branch information
aa7401 committed Nov 22, 2020
1 parent f2e78c6 commit 68da549f207ee27dfc58007460d6e844fd15f25b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
@@ -6,6 +6,12 @@ import Accounts from '../modules/accounts.js'

const router = new Router({ prefix: '/accounts' })

// test route
router.get('/', async ctx => {
ctx.status = 200
ctx.body = {status: 'success', msg: 'server running'}
})

// adds a new account
router.post('/', async ctx => {
try {
@@ -3,6 +3,7 @@

import Router from 'koa-router'
import bodyParser from 'koa-body'
// import cors from 'koa-cors'

import accounts from'./accounts.js'
import foo from'./foo.js'
@@ -18,9 +19,20 @@ async function custom404(ctx, next) {
}
}

async function cors(ctx, next) {
console.log('CORS')
ctx.set('Access-Control-Allow-Origin', '*')
ctx.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
ctx.set('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
ctx.set('Access-Control-Allow-Credentials', true)
await next()
}

const router = new Router()

// router.use(custom404)
// router.use(cors({origin: '*'}))
router.use(cors)
router.use(bodyParser())

const routes = [accounts, foo]

0 comments on commit 68da549

Please sign in to comment.