'Express.js doesn't redirect to custom URL scheme
I'm currently trying to redirect the user to a custom URL scheme with Express.js to open an app installed on my iPad (using "example://").
Here's my code that should redirect to the URL when a button gets pressed on a page running on a different server:
const { response } = require('express');
const express = require('express');
const router = express.Router();
const path = require('path');
const smartMirror = express();
router.get('/', function(req, res){
res.sendFile(path.join(__dirname + '/test.html'));
});
smartMirror.use('/', router);
smartMirror.listen(process.env.port || 8000);
console.log('Running on Port 8000');
smartMirror.get("/launch", (req, res) => {
res.redirect(302, "touchpoint://");
res.status(200);
})
In the console the error says "UnhandledPromiseRejectionWarning: TypeError: node-fetch cannot load [object Request]. URL scheme "touchpoint" is not supported."
What's the problem here?
Solution 1:[1]
You've misidentified the problem. It hasn't go anything to do with Express telling the client it has been redirected, it is because you are trying to access the URL with fetch.
Whatever application touchpoint:// has been registered to be handled with, you need to navigate to the URL.
fetch("touchpoint://") won't work (and this is what you are doing, just via a redirect).
This is for much the same reason that <img src="touchpoint://"> wouldn't work if you tried that.
You need to actually navigate to it. e.g.
<a href="touchpoint://"> or location = "touchpoint://".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Quentin |
