├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── config.default.js ├── configs └── regs.js ├── controllers ├── actions.js ├── getpage.js ├── index.js ├── misc.js ├── notifications.js └── static.js ├── debug └── fcm.js ├── index.js ├── initialize.js ├── lib ├── balancegroup.js ├── context.js ├── taskrunner │ ├── index.js │ └── memoryqueue.js ├── userrequest.js └── utils.js ├── middlewares └── index.js ├── models ├── index.js ├── sql-test.js └── sqls │ ├── followingposts.sql │ ├── notifications.sql │ └── today.sql ├── package-lock.json ├── package.json ├── services ├── autoupdate.js ├── notificationservice.js ├── pageservice.js └── todayservice.js └── tasks └── index.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint:recommended"], 3 | "env": { 4 | "es6": true, 5 | "node": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 2018 9 | }, 10 | "rules": { 11 | "no-constant-condition": "off" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | ll 3 | captcha.png 4 | config.js 5 | database.sqlite 6 | .DS_Store 7 | cookies 8 | lastLoginCache 9 | public -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, The Polymer Authors. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | get-v2ex 2 | ================================ 3 | 4 | RESTful APIs for [V2EX](https://www.v2ex.com). This is the back-end of bv2ex web application. 5 | 6 | ## Changelog 7 | 8 | Notice: Recently automatic update function was added. If you checked out the latest code, it is enabled by default. To disable this feature you need to set `autoUpdate` to `false` in `config.js`. 9 | 10 | To update, see `Update` section below. 11 | 12 | ## BV2EX 13 | 14 |  15 | 16 |  17 | 18 |  19 | 20 | 21 | [bv2ex](https://github.com/7nights/bv2ex) is a redesigned V2EX web application. Its goal is to provide a better user experience and more useful features with new web technologies. 22 | 23 | ## Requirements 24 | Node.js >= 10.15.3 25 | 26 | ## Installation 27 | 28 | ```shell 29 | git clone https://github.com/7nights/get-v2ex.git --depth 1 30 | npm install 31 | npm run init 32 | ``` 33 | 34 | ## Configure FCM 35 | 36 | *(This step is optional.)* You can enable FCM to notifiy users when they get new notifications. This need you to configure both the server side and client side. Follow the instruction below to configure your server. 37 | 38 | ### Step 1. Add a project 39 | 40 | Go to [Firebase console](https://console.firebase.google.com/u/0/) to add a project. 41 | 42 | ### Step 2. Create a server account 43 | 44 | 1. In the Firebase console, open Settings > [Server Accounts](https://console.firebase.google.com/u/0/project/_/settings/serviceaccounts/adminsdk). 45 | 2. Click **Generate New Private Key**, then confirm by clicking **Generate Key**. 46 | 3. Securely store the JSON file containing the key on your server. 47 | 48 | ### Step 3. Edit `config.js` 49 | 50 | 1. Fill in `serverKeyPath` with the absolute path of the key file. 51 | 2. Fill in `databaseURL`. You can find it in the `Admin SDK configuration snippet` at step 2. 52 | 53 | ## Configure Nginx 54 | 55 | Before you configure Nginx, you need to install [bv2ex](https://github.com/7nights/bv2ex) first. 56 | 57 | You may use get-v2ex to serve both the RESTFul APIs and static resources of the web application. 58 | 59 | To achieve this, we need to add 2 rules to tell Nginx how it should rewrite requests. For example, if we configure `clientAddress` as `https://example_domain` in `get-v2ex/public/config.js`, we'll need to rewrite all the client resource requests to add `'/static'` as a prefix. (This is because bv2ex resources are served under the `/static` scope by default.) 60 | 61 | So eventually you may add something like the following to `server` section: 62 | 63 | ```nginx 64 | index static/index.html; 65 | 66 | # configure serverAddress in your config.js as 'https://[your_domain.com]/api' 67 | location ~ ^/api/(.*) { 68 | rewrite ^/api/(.*) /$1 break; 69 | proxy_pass http://127.0.0.1:3001; 70 | } 71 | # treat other requests as static resources 72 | location ~ ^/(.*) { 73 | rewrite ^/(.*) /static/$1 break; 74 | proxy_pass http://127.0.0.1:3001; 75 | } 76 | ``` 77 | 78 | ## Start your server 79 | 80 | You can use some tools to manage your bv2ex server process such as [pm2](https://pm2.io/doc/en/runtime/overview/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding) or [forever](https://www.npmjs.com/package/forever). 81 | 82 | ```shell 83 | npm i -g forever 84 | forever start index.js 85 | ``` 86 | 87 | ## Update 88 | 89 | ```shell 90 | git pull 91 | npm i 92 | forever restart index.js 93 | ``` 94 | -------------------------------------------------------------------------------- /config.default.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | sessionSecret: 'ashid&ASKads(asnd', 3 | fcm: { 4 | // absolute path to your fcm server key 5 | serverKeyPath: '', 6 | databaseURL: '' 7 | }, 8 | // at right now we only support one account per server 9 | cipher: { 10 | // your v2ex username 11 | user: '{{username}}', 12 | // your v2ex password 13 | password: '{{password}}', 14 | // pwa password, 4 numbers. eg. '1234' 15 | code: '{{pwaCode}}' 16 | }, 17 | port: 3001, 18 | autoUpdate: true, 19 | enableDebugMode: false, 20 | // seconds since 00:00:00 21 | popularTodayUpdateTimeInSeconds: 60 * 60 * 17 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /configs/regs.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | USER_REG: //, 3 | PASSWORD_REG: //, 4 | ONCE_REG: //, 5 | GLOBAL_ONCE_REG: /\/signout\?once=(.*?)'; }" class="top">登出<\/a>/, 6 | // is user signed in 7 | LOGON_REG: /confirm\('确定要从 V2EX 登出?'\)/, 8 | CAPTCHA_REG: /[ \n]*