Have ideas to improve npm?Join in the discussion! »

    yeps-cors

    1.0.1 • Public • Published

    YEPS CORS

    YEPS Cross-Origin Resource Sharing (CORS)

    NPM

    npm version Build Status Coverage Status Linux Build Windows Build

    Dependency Status devDependency Status NSP Status

    License GitHub stars GitHub forks GitHub issues Twitter

    How to install

    npm i -S yeps-cors
    

    How to use

    const App = require('yeps');
    const Router = require('yeps-router');
    
    const error = require('yeps-error');
    const logger = require('yeps-logger');
    const server = require('yeps-server');
    
    const cors = require('yeps-cors');
    
    const app = new App();
    const router = new Router();
    
    app.all([
        error(),
        logger(),
        cors(),
    ]);
    
    router.get('/url').then(async (ctx) => {
        ctx.res.statusCode = 200;
        ctx.res.end(data); 
    });
    
    app.then(router.resolve());
    
    server.createHttpServer(app);
    

    Config

    {String|Function(ctx)} origin Access-Control-Allow-Origin, default is request Origin header

    cors({ origin: '*' });
    
    cors({
        origin(ctx) {
            return ctx.req.url !== '/forbin' ? '*' : false;
        },
    });
    

    {String|Array} allowMethods Access-Control-Allow-Methods, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'

    cors({
        allowMethods: 'GET',
    });
    
    cors({
        allowMethods: ['GET', 'POST'],
    });
                
    cors({
        allowMethods: null,
    });
    

    {String|Array} exposeHeaders Access-Control-Expose-Headers

    cors({
        exposeHeaders: 'content-length',
    });
    
    cors({
        exposeHeaders: ['content-length', 'x-header'],
    });
    

    {String|Array} allowHeaders Access-Control-Allow-Headers

    cors({
        allowHeaders: 'X-PINGOTHER',
    });
                
    cors({
        allowHeaders: ['X-PINGOTHER'],
    });
    

    {String|Number} maxAge Access-Control-Max-Age in seconds

    cors({
        maxAge: 3600,
    });
                    
    cors({
        maxAge: '3600',
    });
    

    {Boolean} credentials Access-Control-Allow-Credentials

    cors({
        credentials: true,
    });
    

    YEPS documentation

    Install

    npm i yeps-cors

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • avatar