Skip to content
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

CORS in x.vweb #20708

Closed
2 tasks
MedLabs opened this issue Feb 2, 2024 · 2 comments
Closed
2 tasks

CORS in x.vweb #20708

MedLabs opened this issue Feb 2, 2024 · 2 comments
Assignees
Labels
Feature Request This issue is made to request a feature.

Comments

@MedLabs
Copy link
Contributor

MedLabs commented Feb 2, 2024

Describe the feature

Enabling CORS in a REST API is very important, there is an example created by @spytheman in vweb/cors app.add_header("Access-Control-Allow-Origin", "*")
but in x.vweb it doesn't work, and I think it could be a better and faster way to configure CORS, instead of adding a preflight function on @['/:path...'; options]

Why not add a Context function that takes the CORS config and could be added to before_request if we want the same config to all endpoints, or to be added to some endpoints as an argument...

Use Case

Usually in other frameworks, I import cors library and set the cors options in a variable then app.use(corsOptions)

Proposed Solution

a Context function that takes Origin, Methods etc as arguments...
ctx.set_cors("*", "GET, POST, PUT, DELETE")

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

x.vweb 0.4.4

Environment details (OS name and version, etc.)

V full version: V 0.4.4 8e47c21.804a7bd
OS: linux, "ArcoLinux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 7840HS with Radeon 780M Graphics
Git version: git version 2.43.0
Git vroot status: weekly.2024.05-2-g804a7bdd (10 commit(s) behind V master)
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@MedLabs MedLabs added the Feature Request This issue is made to request a feature. label Feb 2, 2024
@Casper64 Casper64 self-assigned this Feb 2, 2024
@metif12
Copy link
Contributor

metif12 commented Feb 6, 2024

hi.
i looked inside x.vweb module and find out that there is a complete and powerfull cors middleware for handling cors that you can use.

Example:

app.use(vweb.cors[Context](vweb.CorsOptions{
    origin: '*'
    allowed_methods: [.get, .head, .patch, .put, .post, .delete]
}))

@Casper64
Copy link
Member

Casper64 commented Feb 6, 2024

It was added for this issue, I'll close it

@Casper64 Casper64 closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

No branches or pull requests

3 participants