我一直在尝试设置一个基本的 atlassian-connect-express (ACE) 应用程序,并修改了 ACE 包提供的起始代码以适合无服务器部署。这样做后我面临的问题之一是路由现在分为多个阶段,/dev
例如/prod
. 我做了一些研究,发现解决这个问题的一种方法是使用快速路由器并将其安装到要部署到的阶段的适当端点。然后我面临的问题是ACE提供的身份验证中间件似乎是应用程序级别的,并且不能被每个路由器使用。
通常,路由会像这样添加到 express 应用程序中:
import ace from 'atlassian-connect-express';
import express from 'express';
import routes from './routes';
const app = express();
const addon = ace(app);
app.use(addon.middleware());
routes(app, addon);
并且在./routes/index.js
export default function routes(app, addon) {
// Redirect root path to /atlassian-connect.json,
// which will be served by atlassian-connect-express.
app.get('/', (req, res) => {
res.redirect('/atlassian-connect.json');
});
// This is an example route used by "generalPages" module (see atlassian-connect.json).
// Verify that the incoming request is authenticated with Atlassian Connect.
app.get('/hello-world', addon.authenticate(), (req, res) => {
// Rendering a template is easy; the render method takes two params:
// name of template and a json object to pass the context in.
res.render('hello-world', {
title: 'Atlassian Connect'
});
});
// Add additional route handlers here...
}
我已更改./routes/index.js
为作为路由器对象工作并将其导出,但这使我无法使用addon.authenticate()
中间件
import ace from 'atlassian-connect-express';
import express from 'express';
import routes from './routes';
const app = express();
const addon = ace(app);
app.use('/dev', require('./routes'));
并且在./routes/index.js
const express = require('express');
const router = express.Router();
// Redirect root path to /atlassian-connect.json,
// which will be served by atlassian-connect-express.
router.get('/', (req, res) => {
res.redirect('/atlassian-connect.json');
});
// This is an example route used by "generalPages" module (see atlassian-connect.json).
// Verify that the incoming request is authenticated with Atlassian Connect.
router.get('/hello-world', addon.authenticate(), (req, res) => {
// Rendering a template is easy; the render method takes two params:
// name of template and a json object to pass the context in.
res.render('hello-world', {
title: 'Atlassian Connect'
});
});
module.exports = router;
显然不知道addon
,路由器无法使用该认证中间件。
将中间件附加到应用程序时,是否可以将该中间件传递给路由器?如果没有,是否有另一种方法可以在不使用路由器的情况下处理 URL 前缀?