本文整理汇总了TypeScript中cors.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: server
export default function server(session: any): express.Express {
// Init server
const app: express.Express = express();
app.disable('x-powered-by');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser(config.cookiePass));
// Session settings
app.use(expressSession(session));
// CSRF
app.use(csrf({
cookie: false
}));
// CORS
app.use(cors({
origin: true,
credentials: true
}));
app.use((req, res, next) => {
res.header('X-Frame-Options', 'DENY');
next();
});
router(app);
return app;
}
开发者ID:armchair-philosophy,项目名称:Misskey-Web,代码行数:32,代码来源:server.ts
示例2: server
export default function server(): express.Express {
// Init server
const app: express.Express = express();
app.disable('x-powered-by');
// CORS
app.use(cors({
origin: true,
credentials: false
}));
// SVGZ
// see: https://github.com/strongloop/express/issues/1911
app.get(/.svgz/, (req, res, next) => {
res.set({'Content-Encoding': 'gzip'});
next();
});
app.use(express.static(`${__dirname}/resources`));
// Not found handling
app.use((req, res) => {
res.status(404).send('not-found');
});
return app;
}
开发者ID:armchair-philosophy,项目名称:Misskey-Web,代码行数:28,代码来源:resources-server.ts
示例3: runServer
function runServer(schemaIDL: Source, extensionIDL: Source, optionsCB) {
const app = express();
if (extensionIDL) {
const schema = buildServerSchema(schemaIDL);
extensionIDL.body = extensionIDL.body.replace('<RootTypeName>', schema.getQueryType().name);
}
app.options('/graphql', cors(corsOptions))
app.use('/graphql', cors(corsOptions), graphqlHTTP(() => {
const schema = buildServerSchema(schemaIDL);
return {
...optionsCB(schema, extensionIDL),
graphiql: true,
};
}));
app.get('/user-idl', (_, res) => {
res.status(200).json({
schemaIDL: schemaIDL.body,
extensionIDL: extensionIDL && extensionIDL.body,
});
});
app.use('/user-idl', bodyParser.text());
app.post('/user-idl', (req, res) => {
try {
if (extensionIDL === null)
schemaIDL = saveIDL(req.body);
else
extensionIDL = saveIDL(req.body);
res.status(200).send('ok');
} catch(err) {
res.status(500).send(err.message)
}
});
app.use('/editor', express.static(path.join(__dirname, 'editor')));
app.listen(argv.port);
log(`\n${chalk.green('â')} Your GraphQL Fake API is ready to use đ
Here are your links:
${chalk.blue('âŻ')} Interactive Editor:\t http://localhost:${argv.port}/editor
${chalk.blue('âŻ')} GraphQL API:\t http://localhost:${argv.port}/graphql
`);
if (!fileArg) {
log(chalk.yellow(`Default file ${chalk.magenta(fileName)} is used. ` +
`Specify [file] parameter to change.`));
}
if (argv.open) {
setTimeout(() => opn(`http://localhost:${argv.port}/editor`), 500);
}
}
开发者ID:codeaudit,项目名称:graphql-faker,代码行数:60,代码来源:index.ts
示例4: initialize
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
/**
* Initializes the things driver needs before routes and middlewares registration.
*/
initialize() {
if (this.cors) {
const cors = require("cors");
if (this.cors === true) {
this.express.use(cors());
} else {
this.express.use(cors(this.cors));
}
}
}
开发者ID:MrDataScientist,项目名称:routing-controllers,代码行数:17,代码来源:ExpressDriver.ts
示例5: config
private config() {
const app = this.app;
const port = this.normalizePort(process.env.PORT || this.port);
// set server port
app.set('port', port);
// view engine setup
app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger(this.logLevel));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(cors());
app.use(express.static(path.resolve(__dirname + '/client/statics')));
if (process.env.NODE_ENV === 'development') {
// only use in development
app.use(errorhandler({
log: (err, str, req) => this.errorNotification(err, str, req)
}));
}
}
开发者ID:thehachez,项目名称:maduk,代码行数:27,代码来源:app.ts
示例6: configExpressServer
private configExpressServer() {
this.app.use(helmet({
noCache: true,
referrerPolicy: true
}));
// todo CHANGE origin in production mode based on your requirement
this.app.use(cors({
origin: [/https?:\/\/*:*/],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['X-Requested-With', 'Content-Type', 'Content-Length', 'X-Auth-Token', 'X-Auth-User'],
exposedHeaders: ['Content-Type', 'Content-Length', 'X-Auth-Token']
}));
this.app.use(loggerMiddleware);
this.app.use(morgan(this.setting.env == 'development' ? 'dev' : 'combined'));
this.app.use(bodyParser.urlencoded({limit: '50mb', extended: false}));
this.app.use(bodyParser.json({limit: '50mb'}));
// closing connection after sending response ???
this.app.use((req: IExtRequest, res: express.Response, next: express.NextFunction) => {
res.set('Connection', 'Close');
next();
});
this.app.enable('trust proxy');
this.app.disable('case sensitive routing');
this.app.disable('strict routing');
this.app.disable('x-powered-by');
this.app.disable('etag');
}
开发者ID:VestaRayanAfzar,项目名称:express-api-template,代码行数:28,代码来源:ServerApp.ts
示例7: cors
module.exports.cors = function(options){
options = options || {}
options.maxAge = options.maxAge==null ? 3000 : options.maxAge//prevent subsequent OPTIONS requests via cache
options.exposedHeaders=options.exposedHeaders||safeHeaders
options.allowedHeaders=options.allowedHeaders||safeHeaders
return cors(options)
}
开发者ID:AckerApple,项目名称:ack-node,代码行数:7,代码来源:router.ts
示例8: function
mongoose.connection.on('open', function () {
console.error('mongo is open');
var app = express();
app.use(cors());
app.use(cors());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use('/app', express.static(path.resolve(__dirname, 'app')));
app.use('/vendor', express.static(path.resolve(__dirname, 'vendor')));
var photos = require('../server/routes/photos.js')(app);
var users = require('../server/routes/users.js')(app);
app.listen(3000, function (err) {
console.log('This express app is listening on port: 3000');
});
});
开发者ID:jrothrock,项目名称:dosplash,代码行数:18,代码来源:server.ts
示例9: next
swaggerExpress.create(swaggerConfig, function (err, swagger) {
if (err) { throw err; }
app.use(function (req, res, next) {
next();
});
app.use(cors(corsOptions));
swagger.register(app);
app.get(
'/auth/google',
passport.authenticate('google', {
session: false,
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
],
}),
);
app.get('/auth/google/callback',
function (req, res, next) {
passport.authenticate('google', {
session: false,
failureRedirect: api.helpers.Config.settings.ui_base_path,
},
function (error, user: api.models.UserModel, info) {
if (error) { return next(error); }
if (!user) { return res.redirect(api.helpers.Config.settings.ui_base_path); }
try {
let token = jwtService.signToken(user);
// to prevent from csrf attack we sent back a XSRF-TOKEN in a cookie
res.cookie('XSRF-TOKEN', token.xsrf, { maxAge: 900000, httpOnly: false });
res.cookie('JWT-TOKEN', token.jwt, { maxAge: 900000, httpOnly: true });
let isAdmin = 'false';
if (user.roles && user.roles.indexOf('admin') > -1) {
isAdmin = 'true';
}
return res.redirect(`${api.helpers.Config.settings.ui_base_path}/#/login?user_id=${user.id}&is_admin=${isAdmin}`);
} catch (err) {
return next(err);
}
})(req, res, next);
});
app.listen(port);
if (swagger.runner.swagger.paths['/hello']) {
console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
}
});
开发者ID:arandehkharghani,项目名称:tforex-gateway,代码行数:53,代码来源:app.ts
示例10: makeHttpServer
export function makeHttpServer(config: Config) {
const app = express()
const server = new AdminAPI(config)
app.use(expressWinston.logger({
winstonInstance: logger
}))
app.use(cors())
app.post(/\/v1\/admin\/reload/, (req: express.Request, res: express.Response) => {
return server.checkAuthorization(req.headers['authorization'])
.then((authResult) => {
if (!authResult) {
return { statusCode: 403, status: { error: 'forbidden' } }
}
return server.handleReload()
})
.then(reloadStatus => writeResponse(res, reloadStatus.status, reloadStatus.statusCode))
})
app.get(/\/v1\/admin\/config/, (req: express.Request, res: express.Response) => {
return server.checkAuthorization(req.headers['authorization'])
.then((authResult) => {
if (!authResult) {
return { statusCode: 403, status: { error: 'forbidden' } }
}
return server.handleGetConfig()
})
.then((configData) => writeResponse(res, configData.status, configData.statusCode))
})
app.post(
/\/v1\/admin\/config/, express.json(),
(req: express.Request, res: express.Response) => {
return server.checkAuthorization(req.headers['authorization'])
.then((authResult) => {
if (!authResult) {
return { statusCode: 403, status: { error: 'forbidden' } }
}
const newConfig = req.body
return server.handleSetConfig(newConfig)
})
.then((configStatus) => writeResponse(res, configStatus.status, configStatus.statusCode))
})
return app
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:51,代码来源:http.ts
注:本文中的cors.default函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论