我正在使用KMS库使用AWS SDK.我想使用async和await而不是回调.
import AWS, { KMS } from "aws-sdk";
this.kms = new AWS.KMS();
const key = await this.kms.generateDataKey();
Run Code Online (Sandbox Code Playgroud)
但是,当包含在异步函数中时,这不起作用.
我怎么能在这里使用async并等待?
我有一个应用程序,它是一个节点后端和一个反应前端。
当我尝试构建/运行节点应用程序时出现以下错误。
节点: v10.13.0
错误:
dist / index.js:314 regeneratorRuntime.mark(function _callee(productId){^
ReferenceError:未定义regeneratorRuntime
.babelrc
{
"presets": [ [
"@babel/preset-env", {
"targets": {
"node": "current"
},
}
], "@babel/preset-react"],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
{
mode: "development",
entry: "./src/index.js",
target: "node",
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
stats: {
colors: true
},
devtool: "source-map",
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.js",
sourceMapFilename: "index.js.map"
},
module: {
rules: [
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: …Run Code Online (Sandbox Code Playgroud) 我有一个Angualr 6项目,我试图运行以下命令npm run build.如何显示以下错误消息.
ERROR in node_modules/rxjs/internal/symbol/observable.d.ts(4,9): error TS2687: All declarations of 'observable' must have identical modifiers.
node_modules/@types/node/index.d.ts(167,14): error TS2687: All declarations of 'observable' must have identical modifiers.
Run Code Online (Sandbox Code Playgroud)
角度版本
Angular CLI: 6.0.0
Node: 9.8.0
OS: darwin x64
Angular: 6.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0 (cli-only)
@angular/flex-layout 6.0.0-beta.15
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0 (cli-only)
@schematics/update …Run Code Online (Sandbox Code Playgroud) 我正在尝试在gitlab ci管道中构建我的docker映像。
但是,它无法找到docker命令。
/ bin / bash:第69行:docker:找不到命令错误:作业失败:执行远程命令时出错:命令以非零退出代码终止:在Docker容器中执行时出错:1
.gitlab-ci.yml
stages:
- quality
- test
- build
- deploy
image: node:8.11.3
services:
- mongo
- docker:dind
before_script:
- npm install
quality:
stage: quality
script:
- npm run-script lint
test:
stage: test
script:
- npm run-script test
build:
stage: build
script:
- docker build -t server .
deploy:
stage: deploy
script:
- echo "TODO deploy push docker image"
Run Code Online (Sandbox Code Playgroud) 我刚刚在package.json文件中更新了一些软件包。然后npm install我跑了ng serve。但是我现在收到以下错误。
ERROR in ... File '.../node_modules/@types/googlemaps/index.d.ts' is not a module.
... error TS6137: Cannot import type declaration files. Consider importing 'googlemaps' instead of '@types/googlemaps'
Run Code Online (Sandbox Code Playgroud)
我在这里尝试了建议的解决方案- @ types / googlemaps / index.d.ts'不是/// <reference types="@types/googlemaps" />在我的component.ts文件顶部添加的模块,但是这不能解决我的问题,错误仍然存在。
package.json
{
"name": "demo",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.7",
"@angular/cdk": "^6.0.0", …Run Code Online (Sandbox Code Playgroud) 我创建了一个拦截器,该拦截器将令牌附加到仅在功能延迟加载的模块中进行api调用所需的授权标头中。
但是,我不认为拦截器被称为是因为在reports模块中没有显示console.logs。
我读过其他问题,认为这可能与HTTPClientModule有关。此HttpClientModule仅在我的主app.module中进行过一次初始化。
我如何使拦截器仅适用于延迟加载的功能模块。
验证拦截器
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/observable';
import 'rxjs/add/operator/do';
import { AuthService } from './../services/auth/auth.service';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private auth: AuthService) {
console.log('start interceptor');
}
intercept(req: HttpRequest<any>, next: HttpHandler) {
console.log('intercepting');
const authToken = this.auth.getProfileToken();
console.log(authToken);
const authReq = req.clone({
headers: req.headers.set('Authorization', authToken)
});
return next.handle(authReq);
}
}
Run Code Online (Sandbox Code Playgroud)
report.module.ts
import { NgModule } from '@angular/core';
import …Run Code Online (Sandbox Code Playgroud) 我有一个本地环境和一个生产环境.在index.html中,我添加或删除脚本文件,具体取决于环境是本地环境还是生产环境.
我想要一个简单的方法来处理这个问题.里面angular.json有一个file_replacement配置选项.这适用于切换environment.ts到a environment.prod.ts但它似乎不适用于将index.html文件替换为a index.prod.html.
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico",
{
"glob": "**/*",
"input": "../node_modules/font-awesome/fonts",
"output": "/assets/"
}
],
"styles": [
"src/styles/style.scss",
"src/theme.scss",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"scripts": [
"node_modules/hammerjs/hammer.min.js",
"node_modules/auth0-js/build/auth0.min.js",
"node_modules/moment/min/moment.min.js",
"node_modules/ua-parser-js/dist/ua-parser.min.js",
"node_modules/d3/dist/d3.min.js",
"node_modules/wordcloud/src/wordcloud2.js",
"node_modules/chart.js/dist/Chart.bundle.min.js",
"node_modules/progressbar.js/dist/progressbar.min.js"
]
},
"configurations": { …Run Code Online (Sandbox Code Playgroud) 我正在使用请求库进行外部api调用.https://github.com/request/request.我正在使用本机promise/async扩展.https://github.com/request/request-promise-native.
但是我无法检查状态代码,它是未定义的.
public async session(): Promise<any> {
const url = <removed>;
const options = {
uri: url,
headers: {
'Authorization': this.config.token
},
json: true,
body: {
}
}
try {
const res = await request.post(options);
if (res.statusCode !== 200) {
// do something
}
console.log(res);
console.log("statuscode", res.statusCode)
return res;
} catch (err) {
return err;
}
}
Run Code Online (Sandbox Code Playgroud)
res.statusCode未定义.
我从后端资源获取数据并创建角度材料数据表.我一次检索一组50行.
在返回的json对象中,我得到了下一个50行的链接.如何使用此方法实现分页.文档不是很清楚.
list.component.html
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="Identifier">
<mat-header-cell *matHeaderCellDef>Identifier</mat-header-cell>
<mat-cell *matCellDef="let job"> {{job.job_id}} </mat-cell>
</ng-container>
<ng-container matColumnDef="ProductName">
<mat-header-cell *matHeaderCellDef>Product Name</mat-header-cell>
<mat-cell *matCellDef="let job"> {{job.product_id}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Status">
<mat-header-cell *matHeaderCellDef>Status</mat-header-cell>
<mat-cell *matCellDef="let job"> {{job.status}} </mat-cell>
</ng-container>
<ng-container matColumnDef="DateTime">
<mat-header-cell *matHeaderCellDef>Date & Time</mat-header-cell>
<mat-cell *matCellDef="let job"> {{job.reg_time | date:'d/MMM/y HH:mm'}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="show(row)"></mat-row>
</mat-table>
<mat-paginator [pageSize]="15">
</mat-paginator>
Run Code Online (Sandbox Code Playgroud)
list.component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { JobService } …Run Code Online (Sandbox Code Playgroud) 我想运行我的test_integration和build阶段所需的脚本。有没有一种方法可以在之前的脚本中指定它,所以我不必写两次。
before_script:
stage: ['test_integration', 'build']
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用,我在gitlab ci linter中收到以下错误。
状态:语法不正确
错误:before_script配置应为字符串数组
.gitlab-ci.yml
stages:
- security
- quality
- test
- build
- deploy
image: node:10.15.0
before_script:
stage: ['test_integration', 'build']
script:
- apt-get update
- apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
- curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- apt-get -y install docker-ce
- curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker login …Run Code Online (Sandbox Code Playgroud) angular ×5
node.js ×3
angular-cli ×2
docker ×2
gitlab ×2
gitlab-ci ×2
typescript ×2
aws-kms ×1
aws-sdk ×1
babel ×1
express ×1
google-maps ×1
javascript ×1
node-request ×1
webpack ×1