Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default asyncCommand({
description: 'Port to start a server on.',
defaultDescription: 'PORT || 8080',
alias: 'p'
},
cors: {
description: 'Set allowed origins',
defaultDescription: 'https://localhost:${PORT}'
}
},

Expand Down Expand Up @@ -74,11 +78,14 @@ async function serve(options) {
configFile = await tmpFile({ postfix: '.json' });
await fs.writeFile(configFile, JSON.stringify(config));

let port = options.port || process.env.PORT || 8080;

await serveHttp2({
config: configFile,
configObj: config,
server: options.server,
port: options.port || process.env.PORT || 8080,
cors: options.cors || `https://localhost:${port}`,
port,
dir,
cwd: path.resolve(__dirname, '../resources')
});
Expand Down Expand Up @@ -179,19 +186,20 @@ const SERVERS = {
options.cwd = persistencePath('preact-cli');
process.stderr.write(`Falling back to shared directory + simplehttp2server.\n(dir: ${options.cwd})\n`);
}

return [
simplehttp2server,
'-cors', '*',
'-cors', options.cors,
'-config', options.config,
'-listen', `:${options.port || 8080}`
'-listen', `:${options.port}`
];
},
superstatic(options) {
return [
'superstatic',
path.relative(options.cwd, options.dir),
'--gzip',
'-p', options.port || 8080,
'-p', options.port,
'-c', JSON.stringify({ ...options.configObj, public: undefined })
];
},
Expand Down
4 changes: 0 additions & 4 deletions src/resources/static-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"key": "Cache-Control",
"value": "public, max-age=3600, no-cache"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Max-Age",
"value": "600"
Expand Down