UNPKG

803 BJavaScriptView Raw
1const express = require('express')
2const cors = require('cors')
3const serveIndex = require('serve-index')
4module.exports = ({ port, program }) => {
5 const app = express()
6 app.use((req, res, next) => {
7 res.setHeader('Surrogate-Control', 'no-store')
8 res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
9 res.setHeader('Pragma', 'no-cache')
10 res.setHeader('Expires', '0')
11 next()
12 })
13 app.options('*', cors())
14 const corsOptions = {
15 origin: (origin, cb) => {
16 cb(null, { origin: true })
17 }
18 }
19 app.use('/', cors(corsOptions), serveIndex(program.cwd, { icons: true }))
20 app.use('/', cors(corsOptions), express.static(program.cwd))
21 app.listen(port, () => {
22 console.log(`CORS-enabled web server listening on port ${port}`)
23 })
24}