Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fs.watch(apiRootLocation, {
  2.                 recursive: true
  3.             }, () => {
  4.                 clearTimeout(watchTimeout)
  5.                 watchTimeout = setTimeout(() => {
  6.                     invalidateAPI()
  7.                     safeConnectAPI(app)
  8.                     console.log('API updated!')
  9.                 }, 200)
  10.             })
  11.  
  12.  
  13. function safeConnectAPI (app) {
  14.     if (!fs.existsSync(path.resolve(apiRootLocation, 'index.js'))) {
  15.         console.warn(chalk.yellow(`Stub API not found. Please add api from ${apiRootLocation} /index.js`))
  16.         console.warn(chalk.italic.yellow(`
  17.         const router = require('express').Router()
  18.         module.exports = router
  19.         `))
  20.     } else {
  21.         app.use('/api', require(apiRootLocation))
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement