How to use serve-index - 8 common examples

To help you get started, we’ve selected a few serve-index examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nrkno / tv-automation-casparcg-launcher / src / main / http.js View on Github external
})
    }

    // Bind any static paths from the host machine
    const staticPaths = this.config.get('api.staticPaths', [])
    if (staticPaths.length > 0) {
      let basePath = getBasePath(this.config)

      for (let p of staticPaths) {
        if (!path.isAbsolute(p.path)) {
          p.path = path.join(basePath, p.path)
        }

        const handlers = [
          express.static(p.path),
          serveIndex(p.path)
        ]

        if (p.allowDelete) {
          // Add a handler for delete
          handlers.splice(0, 0, function (req, res, next) {
            if (req.method !== 'DELETE') {
              next()
              return
            }

            const fullPath = path.join(p.path, req.url)
            log.info('Deleting file: ' + fullPath)

            fs.unlink(fullPath, err => {
              if (err) {
                if (err.code === 'ENOENT') {
github callmekory / nezuko / src / subprocesses / webServer / index.ts View on Github external
)
        return res.status(401).json({ response: 'API key is incorrect' })
      }

      return true
    }

    const app = express()

    app.use(express.json())
    app.use(cors({ credentials: true, origin: ['http://127.0.0.1:3000'] }))
    app.use(express.static(`${__dirname}/app/build`))

    // Serve out icons folder
    app.use('/icons', express.static(`${__dirname}/../../data/images/icons`))
    app.use('/icons', serveIndex(`${__dirname}/../../data/images/icons`))

    // Home page
    app.get('/', (req, res) => res.sendFile('/index.html'))

    // Get DB info
    app.get('/api/db/app', async (req, res) => {
      const db = await generalConfig.findOne({ where: { id: ownerID } })
      return res.status(200).json(JSON.parse(db.dataValues.config))
    })

    // Set DB info
    app.post('/api/db/app', async (req, res) => {
      Log.info('Web Server', `DB update from [ ${req.ip} ]`)
      const db = await generalConfig.findOne({ where: { id: ownerID } })
      if (req.body.config) {
        await db.update({ config: JSON.stringify(req.body.config) })
github coreyp1 / defiant / lib / plugin / http / response / serveDirectory.js View on Github external
else {
      // Restore the request to its original form.
      request.originalUrl = request.url = originalUrl;
      parseUrl(request);
    }
  }
}

/**
 * Because serveIndex() does not know about Defiant's directory structure,
 * it assumes that all the files' paths are relative to the domain.  We must
 * therefore intercept the function that prints the file listing and inject the
 * proper subdirectory path.
 */
const originalServeIndexHtml = serveIndex.html;
serveIndex.html = function() {
  if (arguments[0].__defiant_discarded) {
    if (arguments[4] == '/') {
      arguments[2].unshift('..');
    }
    arguments[4] = arguments[0].__defiant_discarded + arguments[4];
  }
  originalServeIndexHtml.apply(this, arguments);
};

module.exports = ServeDirectory;
github coreyp1 / defiant / lib / plugin / http / response / serveDirectory.js View on Github external
}
    else {
      // Restore the request to its original form.
      request.originalUrl = request.url = originalUrl;
      parseUrl(request);
    }
  }
}

/**
 * Because serveIndex() does not know about Defiant's directory structure,
 * it assumes that all the files' paths are relative to the domain.  We must
 * therefore intercept the function that prints the file listing and inject the
 * proper subdirectory path.
 */
const originalServeIndexHtml = serveIndex.html;
serveIndex.html = function() {
  if (arguments[0].__defiant_discarded) {
    if (arguments[4] == '/') {
      arguments[2].unshift('..');
    }
    arguments[4] = arguments[0].__defiant_discarded + arguments[4];
  }
  originalServeIndexHtml.apply(this, arguments);
};

module.exports = ServeDirectory;
github GoogleChrome / workbox / gulpfile.babel.js View on Github external
gulp.task('serve', unusedCallback => {
  const port = options.port || 3000;
  const app = express();
  const rootDirectory = projectOrStar === '*' ?
    'projects' :
    path.join('projects', projectOrStar);

  app.use(serveStatic(rootDirectory));
  app.use(serveIndex(rootDirectory, {view: 'details'}));
  app.listen(port, () => {
    console.log(`Serving '${rootDirectory}' at http://localhost:${port}/`);
  });
});
github marp-team / marp-cli / src / server.ts View on Github external
private setup() {
    this.server = express()
    this.server
      .get('*', (req, res, next) =>
        this.preprocess(req, res).then(() => {
          if (!res.finished) next()
        })
      )
      .use(express.static(this.inputDir))
      .use(serveIndex(this.inputDir, { template: this.template.bind(this) }))
  }
github oors / oors / packages / oors-mailer / src / index.js View on Github external
          factory: () => serverIndex(this.getConfig('emailsDir')),
        },

serve-index

Serve directory listings

MIT
Latest version published 7 years ago

Package Health Score

73 / 100
Full package analysis

Popular serve-index functions