|
| 1 | +/** |
| 2 | + * HTTP server, with middleware to set CORS header. |
| 3 | + */ |
| 4 | + |
| 5 | +const liveServer = require('live-server'); |
| 6 | +const PATH = require('path'); |
| 7 | + |
| 8 | +const root = PATH.resolve(__dirname, '..'); |
| 9 | + |
| 10 | +const PARAMS = { |
| 11 | + port: 9001, // Set the server port. Defaults to 8080. |
| 12 | + host: '0.0.0.0', // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP. |
| 13 | + root, // Set root directory that's being served. Defaults to cwd. |
| 14 | + open: false, // When false, it won't load your browser by default. |
| 15 | + ignore: 'scss,my/templates', // comma-separated string for paths to ignore |
| 16 | + file: 'index.html', // When set, serve this file (server root relative) for every 404 (useful for single-page applications) |
| 17 | + wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec. |
| 18 | + // mount: [['/components', './node_modules']], // Mount a directory to a route. |
| 19 | + logLevel: 2, // 0 = errors only, 1 = some, 2 = lots |
| 20 | + middleware: [ |
| 21 | + function setCorsHttpHeader (req, res, next) { |
| 22 | + res.setHeader('Access-Control-Allow-Origin', '*'); |
| 23 | + next(); |
| 24 | + } |
| 25 | + ] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack |
| 26 | +}; |
| 27 | + |
| 28 | +liveServer.start(PARAMS); |
0 commit comments