8000 Allow user-defined function in origin option · Issue #60 · possibilities/micro-cors · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow user-defined function in origin option #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tim-phillips opened this issue May 25, 2019 · 1 comment
Open

Allow user-defined function in origin option #60

tim-phillips opened this issue May 25, 2019 · 1 comment
Labels

Comments

@tim-phillips
Copy link
Collaborator
tim-phillips commented May 25, 2019

@lucasfischer, could you sum up your research so far? like possible ways to approach, etc. Doesn’t need to be too specific, we’ll discuss pros and cons of the different approaches.

@lucasfischer
Copy link

i basically thought of 2 approaches:

Callback

i kind of already implemented this, but it makes the underlying code quite complicated, because of the problems, that callbacks introduce.

Example

const cors = microCors({
	origin(origin, callback) {
		asyncAction(data => {
			if (data === 'foo') {
				callback(undefined, true)
			} else {
				callback(undefined, false)
			}
		})
	},
})
const router = micro(cors(() => ({})))

Promise

i think the callback idea is more fitting for express because express was not made for promises and all that new shiny async/await stuff. but since micro depends on async/await, why not use a promise approach for this case? i think it would be much easier to implement and use.

Example

const cors = microCors({
	async origin(origin) {
		const data = await asyncAction(origin)
		if (data === 'foo') {
			return true
		} else {
			return false
		}
	},
})
const router = micro(cors(() => ({})))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0