I have a question. I have a requirement which needs to get something from local storage and set it as short name in manifest.json. I am building a progressive web app and it is vital to have manifest.json to configure its settings. Do you have any idea how to do it? I would gladly appreciate any kind of help. Thank you!
Asked
Active
Viewed 441 times
-3
-
There's a lot of ways of doing that. Please, give more details about your system, what technologies do you use in frontend and in backend? – waghcwb Oct 22 '18 at 20:27
-
@waghcwb this is for Nodejs/reactjs – bEtTy Barnes Oct 22 '18 at 20:30
-
Do you use any module bundler? (eg: webpack) – waghcwb Oct 22 '18 at 21:47
-
@waghcwb yes I do use webpack :) – bEtTy Barnes Oct 22 '18 at 21:59
1 Answers
0
You can make a endpoint in your system with the data that you want to insert into the manifest.json
, in Express
would be something like this (I didn't worried about security)
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'))
client.js
(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
- 357
- 6
- 12
-
@bEtTyBarnes, It is in `fs.writeFileSync` line.. Rename `'./file.json'` with the path to your `manifest.json` – waghcwb Oct 24 '18 at 03:23
-
Sorry I missed it. Btw, additional question is that will this be added to the index.html inside tags programmatically? – bEtTy Barnes Oct 24 '18 at 21:41