ワークスペース内のルート ディレクトリ内に新しいプロジェクト ( nodeJS ) を作成し、しばらくして、プロジェクトのクライアント側とサーバー側を分離したいと考えました。そのために、プロジェクトのルート ディレクトリ内に 2 つのフォルダー (サーバーとクライアント) を作成し、すべてのファイルとディレクトリを適切なフォルダーに移動しました。
その後、Swaggerがswagger.yamlファイルを見つけることができないと表示されるため、サーバーを起動できません(サーバーフォルダーに移動しました)
{ 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' }
ノード サーバーの config フォルダー内のdefault.yamlファイルを編集しようとしましたが、問題は解決しません。
swagger プロジェクトの構成を新しいラクション (ディレクトリ -> サーバー フォルダー) にポイントする方法はありますか?
デフォルト.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...
編集: 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 );
});