Express 角度通用SSR AWS空请求对象
在此之后,我成功地上传了我的项目。但我遇到了一只拉毛虫,我想知道是否有人能帮忙。我的目标是将所有“/api/**”调用重定向到当前服务器,但是当我尝试获取请求参数或authtoken时,它们是空的,包括POST调用中的request.bodyExpress 角度通用SSR AWS空请求对象,express,aws-lambda,serverless,angular-universal,aws-serverless,Express,Aws Lambda,Serverless,Angular Universal,Aws Serverless,在此之后,我成功地上传了我的项目。但我遇到了一只拉毛虫,我想知道是否有人能帮忙。我的目标是将所有“/api/**”调用重定向到当前服务器,但是当我尝试获取请求参数或authtoken时,它们是空的,包括POST调用中的request.body 在脱机执行无服务器操作时,但在部署到aws之后,我确实看到了请求对象 无服务器 import 'zone.js/dist/zone-node'; import { ngExpressEngine } from '@nguniversal/express
- 在脱机执行无服务器操作时,但在部署到aws之后,我确实看到了请求对象
import 'zone.js/dist/zone-node';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs';
const bodyParser = require('body-parser')
const cors = require('cors')
export const app = express();
const distFolder = join(process.cwd(), 'dist/mainfront/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
app.set('view engine', 'html');
app.set('views', distFolder);
// Serve static files from /browser
app.get('*.*', express.static(distFolder, {
maxAge: '2h'
}));
// All Redirects
app.all('/api/**', (req, res) => {
let authToken = req.get('Authorization'); // token is empty
res.append('authorization', `${authToken}`); // token is empty
console.log(`<< API Redirect Data >> [${req.method}]: ${req.originalUrl}`, req.query, authToken) // req.query, or req.params are empty
res.redirect(301,`https://www.example.com${req.originalUrl}`);
});
// All regular routes use the Universal engine
// DO not edit this
app.get('*', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
export * from './src/main.server';
serverless.yml
service: mainfront
plugins:
- serverless-apigw-binary
- serverless-offline
provider:
name: aws
runtime: nodejs12.x
memorySize: 192
region: us-east-1
timeout: 10
stage: production
package:
exclude:
- ./**
include:
- "node_modules/aws-serverless-express/**"
- "node_modules/binary-case/**"
- "node_modules/type-is/**"
- "node_modules/media-typer/**"
- "node_modules/mime-types/**"
- "node_modules/mime-db/**"
- "dist/**"
- "lambda.js"
custom:
apigwBinary:
types:
- "*/*"
functions:
api:
handler: lambda.universal
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true
service: mainfront
plugins:
- serverless-apigw-binary
- serverless-offline
provider:
name: aws
runtime: nodejs12.x
memorySize: 192
region: us-east-1
timeout: 10
stage: production
package:
exclude:
- ./**
include:
- "node_modules/aws-serverless-express/**"
- "node_modules/binary-case/**"
- "node_modules/type-is/**"
- "node_modules/media-typer/**"
- "node_modules/mime-types/**"
- "node_modules/mime-db/**"
- "dist/**"
- "lambda.js"
custom:
apigwBinary:
types:
- "*/*"
functions:
api:
handler: lambda.universal
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true