getApiHandler() { if (!this.apiHandler) { const app = express(); app.use(cors()); this.serverCore.initApp(app); this.apiHandler = handler(app); } return this.apiHandler; }
start(input = {}) { const port = input.port || this.settings.port; this.app = express(); this.app.use(cors()); this.app.use(express.urlencoded({ extended: false })); this.app.use(express.json()); for (let i = 0; i < this.plugins.length; i += 1) { this.app.use(this.plugins[i]); } if (this.settings.serveBot) { this.app.use(express.static(path.join(__dirname, './public'))); } for (let i = 0; i < this.routers.length; i += 1) { this.app.use(this.settings.apiRoot, this.routers[i]); } if (port && port > 0) { this.app.listen(port, () => { const logger = this.container.get('logger'); logger.info(`${this.settings.tag} listening on port ${port}!`); }); } }
app.use(morgan('dev')) app.use(bodyparser.json()) app.use(cors()) app.use(helmet()) app.use((err, req, res, next) => {
app.use(cors()); app.use(bodyParser.json()); app.use(
cors({ origin: prettyHost.indexOf('http') !== -1 ? prettyHost : `http://${prettyHost}`,
app.use(cors({ origin: function(origin, callback) { if (!origin) { return callback(null, true); } if (config.allowedOrigins.indexOf(origin) === -1 && config.allowedOrigins.indexOf("*") === -1) { var msg = 'The CORS policy for this site does not allow access from the specified Origin.'; return callback(new Error(msg), false); } return callback(null, true); } }));
}; app.use(cors(corsOptions));
function setupMiddleware(app) { app.set('port', process.env.PORT || 3000); app.disable('x-powered-by'); app.set('trust proxy', 1); // express behind proxy doesn't receive X-Forwarded-* header, if false. app .use(morgan('dev')) // http logger .use(cors({ origin: [ 'http://localhost:3001' ] })) .use(express.json({limit: '1mb'})) // default application/json. .use(express.urlencoded({extended: true, limit: '1mb'})); // doesn't handle multipart, use multer. // use api routes app.use(`/${process.env.API_VERSION || 1}`, routes); // catch all error. It doesn't handle errors sent by next(). But we don't need it. app.use((req, res, next) => { return errors.notFound(res); }); return app; }
app.use(bodyParser.text()) const corsMiddleware = cors({ origin, optionsSuccessStatus: 200
app.use(cors()); app.use(compression()); app.use(bodyParser.json());
router.get('/noticelists', cors(accecptURL), function(req, res, next){ let sql; sql ="select title, href, end_date as enddate from notice_lists"; db.query(sql, (error, result) => { if (error) throw error; console.log(result); res.json(result); }) })
SwaggerExpress.create(config, function(err, swaggerExpress) { if (err) { throw err; } app.use(cors()); // install middleware swaggerExpress.register(app); var port = process.env.PORT || 10010; app.listen(port); if (swaggerExpress.runner.swagger.paths['/hello']) { console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott'); } });
middlewares() { // The request handler must be the first middleware on the app this.server.use(Sentry.Handlers.requestHandler()); // Ready to receive request in json format this.server.use(express.json()); // TODO -> Set address of the goeat web application // this.server.use(cors({origin: 'https://somename'})); this.server.use(cors()); }
function server(middlewares, router) { const app = express(); app.use(json()); app.use(middlewares.logRequest()); app.use(cors()); router.dispatch(app); return app; }
async function bootstrap() { const app = await NestFactory.create(ApplicationModule); app.use(cors()); app.use(bodyParser.json()); await app.listen(3001); }