-3

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!

bEtTy Barnes
  • 195
  • 1
  • 2
  • 10

1 Answers1

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