diff --git a/.gitignore b/.gitignore index 7e603f35d0..63cf38395e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ tmp *.iml coverage .env + +.now \ No newline at end of file diff --git a/api/now.js b/api/now.js new file mode 100644 index 0000000000..237d542a41 --- /dev/null +++ b/api/now.js @@ -0,0 +1,10 @@ +const path = require('path'); +const moduleAlias = require('module-alias'); +moduleAlias.addAlias('@', path.join(__dirname, '../lib')); +const logger = require('@/utils/logger'); +logger.clear(); +const s = require('@/app.js').callback(); + +module.exports = (req, res) => { + s(req, res); +}; diff --git a/docs/en/install/README.md b/docs/en/install/README.md index 433a249316..077d88b6fc 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -263,6 +263,10 @@ env_variables: # [END app_yaml] ``` +#### Deploy to Vercel(Zeit Now) + +Project export a now serverless function with a `now.json` configuration,After installing[Vercel(Zeit Now)](https://vercel.com/docs/now-cli),just run `now` in project directory, RSSHub is on now serverless function. + ### Install Under RSSHub's root directory, execute the following commands to launch RSSHub diff --git a/docs/install/README.md b/docs/install/README.md index 205d30f8c9..aef361cf1e 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -267,6 +267,10 @@ env_variables: # [END app_yaml] ``` +#### 部署至 Vercel(Zeit Now) + +项目中导出了 now serverless function 并附带 `now.json`相关配置,安装了[Vercel(Zeit Now)](https://vercel.com/docs/now-cli)之后,只需要在项目中运行`now` 即可部署到 Now 的云函数上。 + ### 安装 在 RSSHub 项目根目录下运行 diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 3c1db4f65c..642f494a7a 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -1,3 +1,4 @@ +const { resolve } = require('path'); const winston = require('winston'); const config = require('@/config').value; @@ -10,10 +11,10 @@ const logger = winston.createLogger({ // - Write all logs error (and below) to `error.log`. // new winston.transports.File({ - filename: 'logs/error.log', + filename: resolve('logs/error.log'), level: 'error', }), - new winston.transports.File({ filename: 'logs/combined.log' }), + new winston.transports.File({ filename: resolve('logs/combined.log') }), ], }); diff --git a/now.json b/now.json new file mode 100644 index 0000000000..6691f392a1 --- /dev/null +++ b/now.json @@ -0,0 +1,7 @@ +{ + "version": 2, + "routes": [ + { "src": "/api/.*", "dest": "/api/now.js" }, + { "src": "/.*", "dest": "/api/now.js" } + ] +}