feat: depoly on now serverless function (#4554)

This commit is contained in:
fengkx
2020-04-28 17:28:57 +08:00
committed by GitHub
parent f5c6d6e100
commit 7902c547cf
6 changed files with 30 additions and 2 deletions

2
.gitignore vendored
View File

@@ -15,3 +15,5 @@ tmp
*.iml *.iml
coverage coverage
.env .env
.now

10
api/now.js Normal file
View File

@@ -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);
};

View File

@@ -263,6 +263,10 @@ env_variables:
# [END app_yaml] # [END app_yaml]
``` ```
#### Deploy to Vercel(Zeit Now)
Project export a now serverless function with a `now.json` configurationAfter installing[Vercel(Zeit Now)](https://vercel.com/docs/now-cli)just run `now` in project directory, RSSHub is on now serverless function.
### Install ### Install
Under RSSHub's root directory, execute the following commands to launch RSSHub Under RSSHub's root directory, execute the following commands to launch RSSHub

View File

@@ -267,6 +267,10 @@ env_variables:
# [END app_yaml] # [END app_yaml]
``` ```
#### 部署至 Vercel(Zeit Now)
项目中导出了 now serverless function 并附带 `now.json`相关配置,安装了[Vercel(Zeit Now)](https://vercel.com/docs/now-cli)之后,只需要在项目中运行`now` 即可部署到 Now 的云函数上。
### 安装 ### 安装
在 RSSHub 项目根目录下运行 在 RSSHub 项目根目录下运行

View File

@@ -1,3 +1,4 @@
const { resolve } = require('path');
const winston = require('winston'); const winston = require('winston');
const config = require('@/config').value; const config = require('@/config').value;
@@ -10,10 +11,10 @@ const logger = winston.createLogger({
// - Write all logs error (and below) to `error.log`. // - Write all logs error (and below) to `error.log`.
// //
new winston.transports.File({ new winston.transports.File({
filename: 'logs/error.log', filename: resolve('logs/error.log'),
level: 'error', level: 'error',
}), }),
new winston.transports.File({ filename: 'logs/combined.log' }), new winston.transports.File({ filename: resolve('logs/combined.log') }),
], ],
}); });

7
now.json Normal file
View File

@@ -0,0 +1,7 @@
{
"version": 2,
"routes": [
{ "src": "/api/.*", "dest": "/api/now.js" },
{ "src": "/.*", "dest": "/api/now.js" }
]
}