Just started using serve and it's great! But, I had a hard time figuring out how to configure it with a custom serve.json file. There were several contributing factors:
Absolute paths to serve.json are not found.
serve --config /app/serve.json build # SILENTLY FAILS
Config path is relative to the path being _served_ not the current working directory.
serve fails silently when --config is set but file is not found.
INFO Discovered configuration in ../serve.json)Documentation does not clearly indicate how to set config file, or what a serve.json file looks like. An example would be helpful here.
+1
I was having a hard time figuring out how serve.json works as well. I didn't know the path was relative to the directory being served. It's working now. Thanks @arel!
Being relative to the served directory really threw me too. Would be good to either have that documented, or just relative to the CWD.
simple fix.. please patch
__current code__:
const loadConfig = async (cwd, entry, args) => {
const files = [
'serve.json',
'now.json',
'package.json'
];
if (args['--config']) {
files.unshift(args['--config']);
}
const config = {};
for (const file of files) {
const location = path.join(entry, file);
//...
}
//...
}
__better methodology__:
const loadConfig = async (cwd, entry, args) => {
const files = [
path.join(entry, 'serve.json'),
path.join(entry, 'now.json'),
path.join(entry, 'package.json')
];
if (args['--config']) {
files.unshift(
path.isAbsolute(args['--config'])
? path.resolve(args['--config'])
: path.join(entry, args['--config'])
);
}
const config = {};
for (const file of files) {
const location = file;
//...
}
//...
}
Most helpful comment
I was having a hard time figuring out how serve.json works as well. I didn't know the path was relative to the directory being served. It's working now. Thanks @arel!