kokororin / pixiv.moe

😘 A pinterest-style layout site, shows illusts on pixiv.net order by popularity.
http://qiita.com/kokororin/items/5c065fb48dcbf61edc6d
MIT License
362 stars 45 forks source link

Error - 403 #60

Closed Kadantte closed 3 years ago

Kadantte commented 3 years ago

Why Am I getting this after I hosted my own deployment of your front-end?

image

kokororin commented 3 years ago

It has been blocked by CORS policy. Should proxy the backend for your own, like Nginx.

Kadantte commented 3 years ago

EDIT: Now it works on my local but I can't get it to work on my deployment I dunno why tbh!

image

OLD-EDIT:

I did it now proxy But how I'm supposed to return these headers? X-Access-Token and X-Kotori-Token.

image

kokororin commented 3 years ago

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

Kadantte commented 3 years ago

Well, I use Fastify to do it!

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"
    }
  ]
}
kokororin commented 3 years ago

Our API has no geoblock, only protected by CloudFlare with default policy

Kadantte commented 3 years ago

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!

Kadantte commented 3 years ago

I'll close this for now till I get the time to do my own investigations!