Serve: Issues setting config file (`serve.json`)

Created on 14 Dec 2018  路  4Comments  路  Source: vercel/serve

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
    
    • This seems like a bug
    • At a minimum, this should be documented in the README, if it's intended behavior
  • Config path is relative to the path being _served_ not the current working directory.

    • I would have expected the path relative to where the command was called.
    • At a minimum, this should be documented clearly in the README
  • serve fails silently when --config is set but file is not found.

    • I would expect an error if the file is missing.
    • At minimum I would expect a warning (similar to when config file is 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.

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!

All 4 comments

+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;
        //...
    }
    //...
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

TamasHuang picture TamasHuang  路  7Comments

donmccurdy picture donmccurdy  路  6Comments

k7sleeper picture k7sleeper  路  7Comments

leo picture leo  路  5Comments

nikitamendelbaum picture nikitamendelbaum  路  6Comments