Comments (5)
Thanks ! it worked!
app.get('/redirect',(req,res)=>{
(res as any).location("/home").sendStatus(301);
})
from opine.
Thanks ! it worked!
app.get('/redirect',(req,res)=>{ (res as any).location("/home").sendStatus(301); })
Released in version 0.5.1
- if you pull done the latest, you will no longer need the any
type casting.
from opine.
Hi @marc2332 I'll take a look at that now - it is most likely a bug 😂
from opine.
Ah! @marc2332 so there is a small bug in the type definitions which is why your IDE is likely complaining that location does not exist (I had forgotten to uncomment since implementing the method!)
As to why (even if you wrote something like (res as any).location("/home")
) this isn't redirecting, it is because res.location()
just sets a Location
header as per the Opine docs.
If you want to perform a redirect, you need to send a response yourself (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location), specifically a status code of 201
or 3xx
depending on the reason for redirecting.
I am updating the types now and will add an example for using the res.location()
method which will look something like:
const app = opine();
app.get("/home", function (req, res, next) {
res.send("Hello Deno!");
});
app.get("/redirect", function (req, res, next) {
res.location("/home").sendStatus(301);
});
app.listen(3000);
console.log("Opine started on port 3000");
console.log("Try opening http://localhost:3000/redirect");
I intend to implement the equivalent of the res.redirect()
that Express has very soon.
from opine.
Done. Please refer to the updated API documentation and the location example --> https://github.com/asos-craigmorten/opine/tree/master/examples/location
from opine.
Related Issues (20)
- Calling req.body.read() in a post or put method crashes deno HOT 2
- Incompatible with Deno 1.14.0 HOT 4
- Dependency error, no exported member default for several dependencies HOT 1
- Cross-Platform Path Separatores in serveStatic HOT 1
- TS2305 ERROR in deps.ts with range-parser default export HOT 2
- Bug on deno std, or opine ??? HOT 4
- Outdated dependencies
- Some (but not all) static files fail to be served - ERR_CONTENT_LENGTH_MISMATCH HOT 11
- Getting a plain Deno Request object from an OpineRequest? HOT 8
- JSON middleware does not work on Deno Deploy HOT 1
- How to read a request received from a html form? HOT 2
- FormData parser middleware is missing HOT 1
- Deno.Buffer will be deprecated in Deno 2.0 HOT 1
- Type incompatibility with Deno 1.20.1 HOT 5
- Opine can't find template views on Deno Deploy HOT 3
- [QUESTION] how to send ReadableStream<Uint8Array>? HOT 2
- Requested module doesn't provide required data HOT 1
- How to upload file?? HOT 1
- Request protocol for WebSocket upgrade request is always http HOT 2
- server-sent-events with opine HOT 1
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 opine.