pwp-app / pixiviz-server

Backend server of Pixiviz
https://pixiviz.pwp.app
Apache License 2.0
9 stars 2 forks source link

How to deploy? #1

Closed Ruriko closed 3 years ago

Ruriko commented 3 years ago

Can I have instructions on how to deploy the API server & image proxy?

Ruriko commented 3 years ago

I ran this command:

yarn
yarn run start

then I get this error:

$ egg-scripts start --daemon --title=egg-server-pixivc-backend
[egg-scripts] Starting egg application at /var/www/api.animeseries.xyz/htdocs/pixiviz-server
[egg-scripts] Run node /var/www/api.animeseries.xyz/htdocs/pixiviz-server/node_modules/egg-scripts/lib/start-cluster {"title":"egg-server-pixivc-backend","baseDir":"/var/www/api.animeseries.xyz/htdocs/pixiviz-server","framework":"/var/www/api.animeseries.xyz/htdocs/pixiviz-server/node_modules/egg"} --title=egg-server-pixivc-backend
[egg-scripts] Save log file to /root/logs
[egg-scripts] Wait Start: 1...
[egg-scripts] tail -n 100 /root/logs/master-stderr.log
[egg-scripts] Got error when startup:
[egg-scripts] (node:13625) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /var/www/api.animeseries.xyz/htdocs/pixiviz-server/node_modules/koa/package.json.
[egg-scripts] Update this package.json to use a subpath pattern like "./*".
[egg-scripts] (Use `node --trace-deprecation ...` to show where the warning was created)
[egg-scripts]
[egg-scripts] Start got error, see /root/logs/master-stderr.log
[egg-scripts] Or use `--ignore-stderr` to ignore stderr at startup.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

master-stderr.log

(node:13625) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /var/www/api.animeseries.xyz/htdocs/pixiviz-server/node_modules/koa/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)

Any fix to this?

backrunner commented 3 years ago
  1. Install dependencies by npm, using yarn may cause some unknown problems.

  2. You need to create a file named key.js in config folder, here's a template:

'use strict';

module.exports = {
  cookie: '',  // secret for cookie encryption
  redis: '', // secret for redis connection
  refreshToken: '' // your pixiv refresh token, more details: https://github.com/upbit/pixivpy/issues/158
};
  1. The image proxy is just a simple nginx reverse proxy, you need to proxy i.pximg.net and set referer to https://www.pixiv.net.

  2. For the questions about egg.js, see their documentations.

Tip: you can modify other redis connection configurations in config/config.default.js.

Ruriko commented 3 years ago

Where do I get the secret for cookie & redis? Do I have to manually get pixiv refresh token everyday or will the script auto refresh the token so it doesn't expire?

backrunner commented 3 years ago

Where do I get the secret for cookie & redis?

Do I have to manually get pixiv refresh token everyday or will the script auto refresh the token so it doesn't expire?

The secret for cookie is a random string, and the secret for redis depends on how you deploy redis on your server, actually it is the connection password. As for the refresh token, you only need to get it manually once when you start your server at the first time.

Ruriko commented 3 years ago

I can't seem to get the image proxy working since I don't exactly know where to proxy the location for i.pximg.net. Can you help me fix mine?

server {
    server_name animeseries.xyz www.animeseries.xyz;
    root /var/www/animeseries.xyz/htdocs/pixiviz/dist;
    index  index.html index.htm;

location / {
    proxy_pass  https://i.pximg.net;
    proxy_set_header Referer "https://www.pixiv.net";
  }

location /api/ {
    proxy_pass http://api.animeseries.xyz/;
  }

}
backrunner commented 3 years ago

Sorry, I can't teach you hand by hand on how to build a image proxy. Maybe you can check this: https://huleski.github.io/2019/10/17/nginx%E8%AE%BE%E7%BD%AE%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E8%AE%BF%E9%97%AEpixiv%E5%9B%BE%E7%89%87/

And you need to set cors headers to make things work right.