I created new project (nodeJS) inside root directory inside my workspace and after some time I wanted to separate client and server side of project. To do that I created two folders (server and client) inside root dir of project and moved all files and directories to appropriate folder.
After that I can't start server because it says that Swagger can't find swagger.yaml file (I moved it to server folder)
{ Error: ENOENT: no such file or directory, open 'C:\Users\User\Documents\movieCollection\api\swagger\swagger.yaml'
at Error (native)
at Object.fs.openSync (fs.js:634:18)
at Object.fs.readFileSync (fs.js:502:33)
at C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:283:44
at findProjectFile (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:308:14)
at readProject (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:268:3)
at Command.edit (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:240:3)
at Command.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\util\cli.js:167:27)
at Command.listener (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\node_modules\commander\index.js:301:8)
at emitTwo (events.js:106:13)
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\User\\Documents\\movieCollection\\api\\swagger\\swagger.yaml' }
I tried to edit default.yaml file inside config folder of node server but problem still persists.
Is there way to point swagger project configuration to new laction (directory-> server folder) ?
default.yaml:
# swagger configuration file
# values in the swagger hash are system configuration for swagger-node
swagger:
fittingsDirs: [ api/fittings ]
defaultPipe: null
swaggerControllerPipe: swagger_controllers # defines the standard processing pipe for controllers
# values defined in the bagpipes key are the bagpipes pipes and fittings definitions
# (see https://github.com/apigee-127/bagpipes)
bagpipes:
_router:
name: swagger_router
mockMode: false
mockControllersDirs: [ ./server/api/mocks ]
controllersDirs: [ ./server/api/controllers ]
_swagger_validate:
name: swagger_validator
validateResponse: true
# pipe for all swagger-node controllers
swagger_controllers:
- onError: json_error_handler
- cors
- swagger_security
- _swagger_validate
- express_compatibility
- _router
# pipe to serve swagger (endpoint is in swagger.yaml)
swagger_raw:
name: swagger_raw
# any other values in this file are just loaded into the config for application access...
EDIT: Added app.js
app.js:
'use strict';
var SwaggerExpress = require('swagger-express-mw');
var express = require("express");
var config = require('config');
var cors = require('cors');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');
var session = require('express-session');
var routes = require('./src/routes');
var routingPath = '../server';
var app = express();
var spec = fs.readFileSync('../server/api/swagger.yaml', 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec);
// Enable CORS
app.use(cors());
// Bootstrap routes
app.use(routes);
// Static files
app.use('/', express.static(__dirname + '/../public'));
module.exports = app; // for testing
var config = {
appRoot: __dirname // required config
};
swaggerExpress.runner.swagger.basePath = routingPath;
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
// install middleware
swaggerExpress.register(app);
var port = process.env.PORT || 10010;
app.listen(port);
console.log('Server started: http://127.0.0.1:' + port );
});