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)
- Add `response` object in route handlers arguments as an alternative to `set` and `cookie`
- Bearer plugin doesn't work on Elysia 1.1.0-rc.9 HOT 1
- Semver not followed correctly HOT 2
- [Sucrose] unexpected isContextPassToFunction error HOT 4
- Type error with global `app.derive` followed by `onError` HOT 4
- `t` is `undefined` when imported from `elysia/type-system` HOT 2
- whitespace minification on application source code breaks `({query }) => ...` HOT 2
- Elysia 1.1 breaks oauth2 plugin on WSL with an Illegal Instruction HOT 2
- cors() doesn't work with new generator function HOT 10
- Setting headers inside generator functions doesn't work HOT 2
- Requesting Clarity for new Streaming Feature HOT 4
- TS linter complains about "body" has implicitly an "any" type for some routes in the same file
- v1.1.0 has a regression in the type for set.headers (no longer supports arrays) HOT 2
- Renaming handler parameters causes hang on start in v1.1.3 HOT 2
- Cannot destructure cookies in derive anymore HOT 1
- staticPlugin response NOT_FOUND HOT 2
- `bun build --minify` does not allow libraries to integrate with Elysia
- Async generator yielding an object results in `[object Object]` output HOT 4
- Async generator handler should follow `text/event-stream` protocol
- cannot destructure in derive 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.