Javascript 有没有办法在manifest.json中获取本地存储对象?
我有个问题。我有一个需求,需要从本地存储中获取一些东西,并在manifest.json中将其设置为短名称。我正在构建一个渐进式web应用程序,让manifest.json配置其设置非常重要。你知道怎么做吗?我很高兴能得到任何帮助。谢谢大家! 您可以在系统中创建一个端点,其中包含要插入到Javascript 有没有办法在manifest.json中获取本地存储对象?,javascript,node.js,reactjs,manifest.json,Javascript,Node.js,Reactjs,Manifest.json,我有个问题。我有一个需求,需要从本地存储中获取一些东西,并在manifest.json中将其设置为短名称。我正在构建一个渐进式web应用程序,让manifest.json配置其设置非常重要。你知道怎么做吗?我很高兴能得到任何帮助。谢谢大家! 您可以在系统中创建一个端点,其中包含要插入到清单中的数据。json,在Express中是这样的(我不担心安全性) server.js const express = require('express') const app = express() const
清单中的数据。json
,在Express
中是这样的(我不担心安全性)
server.js
const express = require('express')
const app = express()
const fs = require('fs')
app.use(express.json())
app.get('/', (req, res) => res.sendfile('./index.html'))
app.post('/', (req, res) => {
fs.writeFileSync('./file.json', JSON.stringify({
description: req.body.description
}, null, 2), (err) => {
if (err) throw err
res.send(`The new description is: ${req.body.description}`)
})
})
app.listen(3000, () => console.log('server is listening'))
(async() => {
const result = await fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: 'only for testing purposes'
})
})
console.log(await result.json())
})()
client.js
const express = require('express')
const app = express()
const fs = require('fs')
app.use(express.json())
app.get('/', (req, res) => res.sendfile('./index.html'))
app.post('/', (req, res) => {
fs.writeFileSync('./file.json', JSON.stringify({
description: req.body.description
}, null, 2), (err) => {
if (err) throw err
res.send(`The new description is: ${req.body.description}`)
})
})
app.listen(3000, () => console.log('server is listening'))
(async() => {
const result = await fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: 'only for testing purposes'
})
})
console.log(await result.json())
})()
有很多方法可以做到这一点。请提供更多关于您的系统的详细信息,您在前端和后端使用了哪些技术?@waghcwb这是针对Nodejs/reactjs的,您是否使用任何模块绑定器?(例如:webpack)@waghcwb是的,我确实使用webpack:)@bEtTyBarnes,它在
fs.writeFileSync
行中。。重命名'./file.json'
,并提供您的manifest.json
路径,很抱歉我错过了它。顺便说一句,另外一个问题是,这将以编程方式添加到index.html内部标记中吗?