Closed Kadantte closed 3 years ago
It has been blocked by CORS policy. Should proxy the backend for your own, like Nginx.
I don't know how you proxy, but with Nginx it's simple.
location /api/ {
proxy_pass https://api.pixiv.moe/;
proxy_ssl_server_name on;
proxy_set_header Host api.pixiv.moe;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
Then can request the "session" api as "https://pixiv.usui.moe/api/session" instead of "https://api.pixiv.moe/session". And the base url should be modified in config file
Well, I use Fastify to do it!
'use strict'
const fastify = require('fastify') const path = require('path')
function build () { const server = fastify({ logger: true })
server.register(require('fastify-cors')) server.register(require('fastify-http-proxy'), { upstream: 'https://api.pixiv.moe', http2: false // optional }) return server } module.exports = build
/api/serverless.js
```js
'use strict'
const build = require('../index')
const server = build()
module.exports = async function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*')
await server.ready()
server.server.emit('request', req, res)
}
vercel.json
{
"version": 2,
"builds": [
{
"src": "api/serverless.js",
"use": "@vercel/node",
"config": {
"helpers": false
}
}
],
"routes": [
{
"src": "/.*",
"dest": "/api/serverless.js"
}
]
}
Our API has no geoblock, only protected by CloudFlare with default policy
Thanks for your reply and help, I try it with my proxy on local it works I dunno why on local works but it doesn't after deploying it on vercel! I'll look into it and see what is wrong on deployment or I might just test on gh-pages!
I'll close this for now till I get the time to do my own investigations!
Why Am I getting this after I hosted my own deployment of your front-end?