cds-snc / node-starter-app

Quick start application setup.... because you have to start somewhere.
MIT License
5 stars 3 forks source link

Simplify getViewData + getDefaultMiddleware #64

Closed timarney closed 4 years ago

timarney commented 4 years ago

Update getViewData and getDefaultMiddleware to handle "spreading" the data vs the user doing this in the routes.

Current

app
    .get(route.path, (req, res) => {
      const jsFiles = ['js/file-input.js']
      res.render(name, { ...routeUtils.getViewData(req), jsFiles })
    })
    .post(route.path, [
      ...routeUtils.getDefaultMiddleware({ schema: Schema, name: name }),
    ])

Future


app
    .get(route.path, (req, res) => {
      const jsFiles = ['js/file-input.js']
      const customVars =  {jsFiles, othervars: {something: true}}
      // remove the ...spread_operators from here
      res.render(name, routeUtils.getViewData(req, customVars))
    })
    .post(route.path, routeUtils.getDefaultMiddleware({ schema: Schema, name: name }))