lau1944 / bunrest

An express-like API for bun server
MIT License
285 stars 31 forks source link

Are there any solutions to solve the CORS problem? #2

Closed wittyCodeX closed 2 years ago

wittyCodeX commented 2 years ago

Hi, Developers. Hope you are doing well. I am developing Restful API using bunrest framework. The problem I facing is CORS issue. I tried to solve the issue using cors npm like in express.js

Here are some of my code snaps.

import { Server } from 'bunrest' import cors from 'cors'

const app = new Server(); app.use(cors());

app.get('/api/endpoint', (req, res) => { // handler here )

The errors I got is like this:

if (Array.isArray(header)) { 149 | applyHeaders(header, res); 150 | } else if (header.key === 'Vary' && header.value) { 151 | vary(res, header.value); 152 | } else if (header.value) { 153 | res.setHeader(header.key, header.value); ^ TypeError: res.setHeader is not a function. (In 'res.setHeader(header.key, header.value)', 'res.setHeader' is undefined) at applyHeaders (/home/legend/aib-bot/node_modules/cors/lib/index.js:153:10) at applyHeaders (/home/legend/aib-bot/node_modules/cors/lib/index.js:149:10) at applyHeaders (/home/legend/aib-bot/node_modules/cors/lib/index.js:149:10) at cors (/home/legend/aib-bot/node_modules/cors/lib/index.js:187:6) at /home/legend/aib-bot/node_modules/cors/lib/index.js:224:16 at /home/legend/aib-bot/node_modules/cors/lib/index.js:214:14 at /home/legend/aib-bot/node_modules/cors/lib/index.js:219:12 at /home/legend/aib-bot/node_modules/cors/lib/index.js:199:8 at corsMiddleware (/home/legend/aib-bot/node_modules/cors/lib/index.js:204:6) at /home/legend/aib-bot/node_modules/bunrest/src/utils/chain.ts:7:12 at /home/legend/aib-bot/node_modules/bunrest/src/utils/chain.ts:19:23 at fetch (/home/legend/aib-bot/node_modules/bunrest/src/server/server.ts:1

Please let me know how to fix the issue?

Kindly Regards

lau1944 commented 2 years ago

The request object inside the (req,res) => {}function is a bun request object, it's a different object from nodejs. I am still trying to work on that and make them compatible. But it probably not gonna resolve soon, I am kinda busy lately.

wittyCodeX commented 2 years ago

Thank you for your replying me. I am really appreciated with your hard work. I am a full stack developer with significant experiences. Please let me know in where there are something I can help you. This is my telegram ID @crypto_phantomguru1524. My email address is jonathan.cryptoguru@gmail.com Please don't hesitate to contact me if you are interested in my proposal.

Best Regards

lau1944 commented 2 years ago

Thank you for your replying me.

I am really appreciated with your hard work.

I am a full stack developer with significant experiences.

Please let me know in where there are something I can help you.

This is my telegram ID @crypto_phantomguru1524.

My email address is jonathan.cryptoguru@gmail.com

Please don't hesitate to contact me if you are interested in my proposal.

Best Regards

You are welcome to pull request anytime.

lau1944 commented 2 years ago

@ethancrypto check out v1.1.0 if the cors is working.