Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config folder at root instead of custom folder #987

Closed
woodgates opened this issue Sep 9, 2018 · 10 comments
Closed

config folder at root instead of custom folder #987

woodgates opened this issue Sep 9, 2018 · 10 comments

Comments

@woodgates
Copy link

woodgates commented Sep 9, 2018

Steps to reproduce

Hi.
I have this repo trying to make nuxt to work with feathers3.2 and its CLI.
https://github.com/woodgates/feathers-nuxt

The configuration is at "server/config" folder. As set in the documents I have my app.js with

const path = require('path');
process.env['NODE_CONFIG_DIR'] = path.join(__dirname, 'config/');

When I create the first service with "feathers generate services" all works good except for the database configuration which is stored in the root/config folder instead of root/server/config.

So when I run npm run dev I got
TypeError: Path must be a string. Received undefined

Expected behavior

The database configuration should be stored on the root/server/config/default.json file.

Actual behavior

The database configuration is stored on the root/config/default.json file.

System configuration

Module versions (especially the part that's not working):
part of package.json:
"directories": {
"lib": "server",
"test": "test/"
},
"dependencies": {
"@feathersjs/configuration": "^2.0.2",
"@feathersjs/express": "^1.2.5",
"@feathersjs/feathers": "^3.2.1",
"feathers-nedb": "^3.1.0",,
"nuxt": "^1.4.2",

NodeJS version:
8.11.4
Operating System:
I working with Linux Mint 19.

Browser Version:
Chromium
React Native Version:

Module Loader:
npm

@daffl
Copy link
Member

daffl commented Sep 10, 2018

It is important that this happens before the const configuration = require('@feathersjs/configuration') call.

@woodgates
Copy link
Author

woodgates commented Sep 10, 2018

@daffl
It's before. This is part of the app.js

'use strict'
const path = require('path');
process.env['NODE_CONFIG_DIR'] = path.join(__dirname, 'config/');

const compress = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const logger = require('./logger');


const feathers = require('@feathersjs/feathers')
const configuration = require('@feathersjs/configuration');

@daffl
Copy link
Member

daffl commented Sep 10, 2018

Have a look at the node-config Wiki but I don't think node-config allows configuring from two different folders. All your configuration files have to be in one place.

@woodgates
Copy link
Author

@daffl
I dont want my configuration in two places. I want the configuration to be at "server/config" folder but the feathers cli is ignoring this.

@daffl
Copy link
Member

daffl commented Sep 12, 2018

I don't understand what the problem is then. If you set

const path = require('path');
process.env['NODE_CONFIG_DIR'] = path.join(__dirname, 'config/');

const configuration = require('@feathersjs/configuration')l

The expected folder will be config/ within the folder of app.js (usually src/, so root/src/config). I just tested this with the feathers-chat and it works as expected.

If you want it at root/config you do not have do anything. If you want it at root/server/config it has to be

process.env['NODE_CONFIG_DIR'] = path.join(__dirname, '..', 'server', 'config/');

@woodgates
Copy link
Author

Hi @daffl

I forgot to mention that my app.js is at the server folder.
root/server/app.js
root/server/config/default.js

Does this change anything?

@daffl
Copy link
Member

daffl commented Sep 13, 2018

It shouldn't. I also just cloned your repository and everything seems to be working fine so I really don't understand what the problem is. The error TypeError: Path must be a string. Received undefined is happening in a default setup if app.get('public') isn't set (during favicon setup in https://github.com/feathersjs/feathers-chat/blob/master/src/app.js#L31) but you appear to have it removed.

@woodgates
Copy link
Author

woodgates commented Sep 13, 2018

Hi @daffl
According to Configuration docs:
"e.g., In server/app.js:
process.env['NODE_CONFIG_DIR'] = path.join(__dirname, 'config/')
const configuration = require('@feathersjs/configuration')
The above code is portable, so you can keep your config/ directory with the rest of your Feathers files. It will work, for example, even if you change the directory from server/ to amazing-server, etc."

This is what happens when I create the first service:

jorge@jorge-VirtualBox:~/Dropbox/www/feachat2$ feathers generate service
? What kind of service is it? NeDB
? What is the name of the service? messages
? Which path should the service be registered on? /messages
? What is the database connection string? nedb://../data
   create config/default.json      <==== this should modify root/server/config/default.json not create a new root/config/default.json file
   create server/services/messages/messages.service.js
    force server/services/index.js
   create server/models/messages.model.js
   create server/services/messages/messages.hooks.js
   create test/services/messages.test.js

@daffl
Copy link
Member

daffl commented Sep 13, 2018

The problem is that generator does not run the application so there is no way for it to know about the change that has been made to NODE_CONFIG_DIR.

One solution would be for the generator to add a directories.config (defaulting to config) section in the package.json which can be done in https://github.com/feathersjs/feathers/blob/master/packages/generator-feathers/generators/app/configs/package.json.js#L23-L26:

directories: {
  lib,
  test: 'test/'
},

The generator can then use that directory (or the default) in https://github.com/feathersjs/feathers/blob/master/packages/generator-feathers/generators/connection/index.js#L141-L144 when writing the configuration:

this.fs.writeJSON(
  this.destinationPath(this.pkg.directories.config, 'default.json'),
  config
);

This would allow to customize the location of the generated configuration files.

@daffl
Copy link
Member

daffl commented Jan 5, 2019

This has been released in the latest @feathersjs/cli.

@daffl daffl closed this as completed Jan 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants