cors's notebooks

  • swagger - /cors/rest
    Last edited 7 years ago
    api = ` # a demonstration of API spec in YAML swagger: '2.0' info: title: Test API version: '1.0.0' paths: /products: get: description: | The products in the proper display order. parameters: - name: id in: path required: true type: number tags: - Products responses: 200: description: An array of product schema: type: array items: $ref: '#/definitions/Product' definitions: Product: properties: name: type: string ` api = require('yamljs').parse(api)
  • Untitled - /cors/graphql
    Last edited 7 years ago
    var model = ({ users: [ { name: 'nh', id: 2 }, { name: 'Ha', id: 1 } ], posts: [ { title: "sfhs post", userId: 2 }, { title: "Ha's post", userId: 1 }, { title: "Ha's second post", userId: 1 } ] }) var schema = require('graph.ql')(` type User { name: String id: Int } type Post { title: String userId: Int user: User } type Query { users: [User] posts(uid: Int): [Post] } `, { Post: { user: self => model.users.filter(({id}) => self.userId == id)[0] }, Query: { users: () => model.users, posts: (self, {uid}) => uid ? model.posts.filter(({userId}) => uid == userId) : model.posts } }) var { compose } = require('redux') var app = require('notebook')('tonic/express-endpoint/1.0.0')(module.exports) var graphql = require('express-graph.ql') app.post('/', graphql(schema))
  • cors proxy - /cors/proxy
    Last edited 7 years ago
    app = require('notebook')('tonic/express-endpoint/1.0.0')(module.exports) request = require('request') app.use(require('cors')()) app.use('/', (req, res) => req.pipe( request(req.url.slice(1)) ).pipe(res) )