我正在设置一个支持离线浏览的渐进式 Web 应用程序。
我已经为我的主要路由 ('domainsample.com/') 设置了离线浏览,即使离线它也会响应 200。
但是当我导航到其他路由 ('domainsample.com/about') 时,我收到一个No Internet Page错误。
这是我在 Heroku 中部署的示例 URL:https : //pwa-hehe.herokuapp.com
我使用 Vue CLI 3 设置项目,使用 Node.js 和 Express.js 在服务器中运行我的 dist 文件夹。
// server.js
const express = require('express')
const path = require('path')
const history = require('connect-history-api-fallback')
const app = express()
const staticFileMiddleware = express.static(path.join(__dirname + '/dist'))
app.use(staticFileMiddleware)
app.use(history({
disableDotRule: true,
verbose: true
}))
app.use(staticFileMiddleware)
app.get('/', function (req, res) {
res.render(path.join(__dirname + '/dist/'))
})
var server = app.listen(process.env.PORT || 3000, function …Run Code Online (Sandbox Code Playgroud) offline-caching vue.js progressive-web-apps vue-router vue-cli-3
所以我有一个 Node /w Typescript REST API,我有注册方法,它创建一个用户并使用创建的用户 firstName、lastName、email 进行响应。
问题是我遇到了这个打字稿错误,上面写着“类型‘文档’缺少‘SavedUser’类型中的以下属性:firstName、lastName、email”。
我相信它在我的 SavedUser 界面中添加 mongoose.Document 类型,我不确定,谢谢你的帮助!
示例代码:
interface SavedUser {
firstName: string
lastName: string
email: string
}
...
public async signUp(req: Request, res: Response): Promise<void | Response> {
const salt: string = await bcrypt.genSalt(10)
const hashedPassword: string = await bcrypt.hash(req.body.password, salt)
const user = new User({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
password: hashedPassword
})
try {
const { firstName, lastName, email }: SavedUser = await user.save()
return res.status(200).send({
firstName,
lastName, …Run Code Online (Sandbox Code Playgroud) if (!challengeType) {
const { brawl, fight }: any = await userModel
.findOneAndUpdate(
{ _id: req.userData._id },
{ $inc: { 'fight.remaining': -1 } },
{ 'new': true }
)
} else {
const { brawl, fight }: any = await userModel
.findOneAndUpdate(
{ _id: req.userData._id },
{ $inc: { 'brawl.remaining': -1 } },
{ 'new': true }
)
}
// typescript error here
// "Cannot find name brawl", and "Cannot find name fight"
console.log(brawl, fight)
Run Code Online (Sandbox Code Playgroud)
不知道为什么打字稿找不到名字 brawl 和打架,这可能是打字稿在 if else …
我有点困惑 promise.all 是如何工作的,它是否并行运行 promise 数组?
所以这是一个示例代码
// index.js
const getSomething = async (args) => {
return await apiCallHere(args)
}
// Create Array of Promises
const arrayOfPromises = sampleArray.map(sample => new Promise((resolve, reject) => {
try {
const something = this.getSomething(sample, args)
resolve(something)
} catch (error) {
reject(error)
}
}))
await Promise.all(arrayOfPromises)
Run Code Online (Sandbox Code Playgroud)
据我观察, Promise.all 并行运行承诺,并等待所有承诺完成。
node.js ×3
javascript ×2
typescript ×2
mongoose ×1
promise ×1
vue-cli-3 ×1
vue-router ×1
vue.js ×1