我正在使用NodeJS,express,express-resource和Sequelize创建一个RESTful API,用于管理存储在MySQL数据库中的数据集.
我正在试图找出如何使用Sequelize正确更新记录.
我创建了一个模型:
module.exports = function (sequelize, DataTypes) {
return sequelize.define('Locale', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
locale: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
len: 2
}
},
visible: {
type: DataTypes.BOOLEAN,
defaultValue: 1
}
})
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的资源控制器中,我定义了一个更新操作.
在这里,我希望能够更新id与req.params变量匹配的记录.
首先,我构建一个模型,然后我使用该updateAttributes方法来更新记录.
const Sequelize = require('sequelize')
const { dbconfig } = require('../config.js')
// Initialize database connection
const sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password)
// Locale model
const Locales = sequelize.import(__dirname …Run Code Online (Sandbox Code Playgroud) 我想启用的WebPack HMR中的NodeJS写在项目打字稿.
但是module.hot不可用:
@ types/webpack-env定义:
declare var module: __WebpackModuleApi.Module
Run Code Online (Sandbox Code Playgroud)哪个与@ types/node定义冲突:
declare var module: NodeModule
Run Code Online (Sandbox Code Playgroud)删除@ types/node,解决了问题,但禁用了process:
process.env.NODE_ENV === 'production' // [ts] Cannot find name 'process'
Run Code Online (Sandbox Code Playgroud) 承认我有这样的功能
const createPerson = () => ({ firstName: 'John', lastName: 'Doe' })
Run Code Online (Sandbox Code Playgroud)
如果在声明之前没有声明接口或类型,我怎么能createPerson得到返回值类型?
像这样的东西:
type Person = typeof createPerson()
Run Code Online (Sandbox Code Playgroud)
我有一个Redux容器,它将状态和调度操作映射到组件的props.
import { CounterState } from 'reducers/counter'
// ... Here I also defined MappedState and mapStateToProps
// The interface I would like to remove
interface MappedDispatch {
increment: () => any
}
// And get the return value type of this function
const mapDispatchToProps =
(dispatch: Dispatch<State>): MappedDispatch => ({
increment: () => …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 webpack 编译我的 Sass。编译正常的 sass 没问题,但出现错误。
Module not found: Error: Can't resolve '../img/twitter.svg' in '/Users/Steve/mywebsite/scss'
@ ./~/css-loader!./~/sass-loader/lib/loader.js!./scss/main.scss 6:94501-94530
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题?或者,有没有办法将 sass 编译器的级别设置为不那么严格以忽略某些错误
下面是我目前的配置。
const path = require("path");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
resolve: {
alias: {
masonry: "masonry-layout",
isotope: "isotope-layout",
},
},
entry: "./main.js",
output: {
path: path.resolve(__dirname, "./dist/dist2"),
filename: "bundle.js",
},
module: {
rules: [
{
test: /\.(png|jpg|svg)$/,
include: path.join(__dirname, "/dist/img"),
loader: "url-loader?limit=30000&name=images/[name].[ext]",
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader?presets[]=es2015",
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: …Run Code Online (Sandbox Code Playgroud) 正如文档所述,它们都处理将非流插件转换为流.
我试着理解的是,如果我可以.pipe()在某些东西上使用这个方法,那么这不是说它是一个流吗?
如果是这样,我该怎么转换成什么?
(来自:https://www.npmjs.com/package/vinyl-buffer)
var browserify = require('browserify')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var uglify = require('gulp-uglify')
var size = require('gulp-size')
var gulp = require('gulp')
gulp.task('build', function() {
var bundler = browserify('./index.js')
return bundler.pipe()
.pipe(source('index.js'))
.pipe(buffer()) // <---------------------- why?
.pipe(uglify())
.pipe(size())
.pipe(gulp.dest('dist/'))
})
Run Code Online (Sandbox Code Playgroud)
(来自:https://www.npmjs.com/package/vinyl-source-stream)
var source = require('vinyl-source-stream')
var streamify = require('gulp-streamify')
var browserify = require('browserify')
var uglify = require('gulp-uglify')
var gulp = …Run Code Online (Sandbox Code Playgroud) 有两种类型
type A = {
x: number
y: number
}
type B = {
y: number
z: number
}
Run Code Online (Sandbox Code Playgroud)
如何获得具有该类型的共同属性的类型?
type C = Something<T1, T2> // { y: number }
Run Code Online (Sandbox Code Playgroud) 我需要使用JavaScript加载和读取XML文件.
以下代码在Firefox,IE和Opera中运行良好:
function loadXMLDoc(dname) {
var xmlDoc
// Internet Explorer
try {
xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
}
catch (e) {
// Firefox, Opera, etc.
try {
xmlDoc = document.implementation.createDocument('', '', null)
}
catch (e) {
alert(e.message)
}
}
try {
xmlDoc.async = false
xmlDoc.load(dname)
return xmlDoc
}
catch (e) {
alert(e.message)
}
return null
}
Run Code Online (Sandbox Code Playgroud)
但是在Chrome中执行此代码会给我带来以下错误:
对象#没有方法"加载"
我在Express网站上遇到了问题,该网站使用SVG和其他文件,如字体.
在本地运行应用程序时没有任何问题,但一旦部署在Azure上,SVG和字体就不再出现了.
web.config在项目根目录创建了一个文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".woff" mimeType="application/x-woff" />
<mimeMap fileExtension=".ttf" mimeType="application/x-woff" />
</staticContent>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
也用这个解决方案:( 在windows azure中的Svgs和其他mime类型)
这两种解决方案现在都允许加载SVG文件,但不再加载网页.(HTTP 500)
它似乎覆盖了动态内容的配置.
如何配置动态内容以使应用程序再次运行?
我正在构建一个 ionic 应用程序,该应用程序从 iTunes 中获取 rss 提要。我能够获取 rss 提要并在我的应用程序上显示条目。
我收到此错误,想了解如何正确设置变量。
export class MyPage {
episodes: any;
...
getRssFeed() {
this.rssProvider.getFeed(this.rssUrl)
.then(data => {
console.log(data);
this.episodes = data.items;
});
}
}
Run Code Online (Sandbox Code Playgroud)
rssProvider.ts
...
getFeed(rssUrl: string) {
try {
return new Promise(resolve => {
this.http.get(`${this.baseUrl}?rss_url=${rssUrl}&api_key=${this.apiKey}&count=${this.count}`).subscribe(data => {
resolve(data);
}, error => {
console.error(error);
});
});
} catch (error) {
console.error('Something really bad happened trying to get rss feed.');
console.error(error);
}
}
Run Code Online (Sandbox Code Playgroud)
如果这有任何意义,我将 WebStorm 用于我的 IDE。
这是我得到的错误:
Typescript Error:
Property 'items' does not …Run Code Online (Sandbox Code Playgroud) My Electron主进程使用TypeScript和捆绑的Webpack 2编写.
通过ts-loader和完成穿脱babel-loader.
发展模式,开始webpack --watch与主要工艺配置.
我无法使用VSCode调试器调试主进程.
在入口点添加断点src/main/index.ts没有任何影响.
.vscode/launch.js{
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeArgs": [
"${workspaceRoot}",
"--remote-debugging-port=9222"
],
"sourceMaps": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
webpack.development.js{
target: 'electron',
devtool: 'source-map',
entry: {
main: join(__dirname, 'src/main/index')
},
output: {
path: join(__dirname, 'app'),
filename: '[name].js'
}
}
Run Code Online (Sandbox Code Playgroud) 我希望我的Azure函数之一执行HTTP重定向。
这是该函数的当前代码:
module.exports = context => {
context.res.status(302)
context.res.header('Location', 'https://www.stackoverflow.com')
context.done()
}
Run Code Online (Sandbox Code Playgroud)
但这行不通。
邮递员发送的请求显示响应如下:
Status:200Location 没有设置这是正确的代码吗?还是Azure Functions根本不允许这样做?
typescript ×5
javascript ×4
node.js ×3
webpack ×3
azure ×2
debugging ×1
electron ×1
express ×1
gulp ×1
mime-types ×1
mysql ×1
sass-loader ×1
sequelize.js ×1
svg ×1
web-config ×1
webpack-hmr ×1
webstorm ×1
xml ×1
xmldom ×1