Comments (2)
I assume that you post this on Discord as well, so basically just use
set.headers['AnyHeader'] = 'Value'
instead of
set.headers = { AnyHeader: 'a' }
from elysia.
If you are still strugling, I managed to get this to work following this:
app.onAfterHandle(({ request, set }) => {
if (!Bun.env.FRONTEND_URL) return false;
set.headers["Access-Control-Allow-Origin"] = Bun.env.FRONTEND_URL;
if (request.method === "OPTIONS") {
set.headers["Access-Control-Allow-Headers"] =
request.headers.get("Access-Control-Request-Headers") ??
"Content-Type, Authorization";
set.headers["Access-Control-Allow-Credentials"] = "true";
set.headers["Access-Control-Allow-Methods"] =
"GET, POST, DELETE, PUT, PATCH";
}
});
app.use(
cors({
methods: ["GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS"],
origin: Bun.env.FRONTEND_URL,
credentials: true,
allowedHeaders: [
"Content-Type",
"Authorization",
"Access-Control-Allow-Headers",
"Access-Control-Allow-Credentials",
"Access-Control-Request-Headers",
],
})
);
from elysia.
Related Issues (20)
- Allow multiple handlers with same path in something like guard
- Having "success" or "statusCode" method in handler like "error" to response 201/204 status code.
- request: matrix room HOT 1
- Allow `.derive` to take additional data HOT 2
- Support for route meta HOT 1
- TypeBox errors are stringified instead of returning object
- Support tRPC v11 HOT 1
- Make Elysia easier to maintain and debug by setting aot: false by default
- Error from body-parser when sent `Content-Type` header without body HOT 4
- Sveltekit integration doesn't work
- Consider using ajv instead of typebox for schema validation HOT 2
- MESSY ERROR `NOT FOUND` HOT 4
- Custom errors thrown in `onRequest` do not get proper `code` set in `onError` HOT 2
- Body type will be unknown if strictNullChecks not enabled HOT 1
- Add Default .gitignore to Prevent Committing .env Files HOT 3
- Custom errors thrown in `onRequest` are not usable when caught in `onError` in `1.1.6`
- Error from sending empty body multipart/form-data HOT 1
- Global websocket publish() not possible HOT 2
- Unable to upload multiple File types from Elysiajs v.0.8>. In v0.7.21 was working well HOT 5
- tRPC Mutation or Query no found on path HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elysia.