Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Chatto von Terpa
@Chatto
idk
module.exports = {


  friendlyName: 'Add',


  description: 'Add projects.',


  inputs: {
    name:{
      type:'string',
      required: true
    },
    description:{
      type:'string',
      required: true
    }
  },


  exits: {

  },


  fn: async function (inputs) {

    var project = await Projects.create({name: inputs.name, description: inputs.description});
    // All done.
    return{
      project: project
    };

  }


};
this is my add action for Projects
and I have this in my routes
  'POST /api/v1/projects/add': {action: 'projects/add'},
when I send
```
http://localhost:1337/projects/add?name=Rising Tide&description=Fantasy Sci-fi MMORPG
http://localhost:1337/projects/add?name=Rising Tide&description=Fantasy Sci-fi MMORPG
it comes back empty
what am I doing wrong?
Chatto von Terpa
@Chatto
Okay I added 'POST /projects/add': {action: 'projects/add},
that got it working...but am I supposed to use /api/v1/projects/add instead?
Chatto von Terpa
@Chatto
I am getting this error from sails
Error: The photo upload failed: Error: Invalid stream: Any chance you forgot to include `files: ['nameOfSomeInput']` at the top level of your actio
this is my /files/add action
module.exports = {


  friendlyName: 'Add',


  description: 'Add Files.',

  files: ['image'],


  inputs: {

    photo: {
      description: 'Upstream for an incoming file upload.',
      type: 'ref'
    },


  },


  exits: {

    success: {
      outputDescription: 'The newly created `Thing`.',
      outputExample: {}
    },

    noFileAttached: {
      description: 'No file was attached.',
      responseType: 'badRequest'
    },

    tooBig: {
      description: 'The file is too big.',
      responseType: 'badRequest'
    },

  },


  fn: async function ({image}) {

    var url = require('url');
    var util = require('util');

    // Upload the image.
    var info = await sails.uploadOne(image, {
      maxBytes: 3000000
    })
    // Note: E_EXCEEDS_UPLOAD_LIMIT is the error code for exceeding
    // `maxBytes` for both skipper-disk and skipper-s3.
    .intercept('E_EXCEEDS_UPLOAD_LIMIT', 'tooBig')
    .intercept((err)=>new Error('The photo upload failed: '+util.inspect(err)));

    if(!info) {
      throw 'noFileAttached';
    }

    // Create a new "thing" record.
    var file = await Files.create({
      filename: info.fd,
      filetype: info.type
    }).fetch();

    var fileSrc = url.resolve(sails.config.custom.baseUrl, '/api/v1/things/'+file.id+'/photo');

    // Return the newly-created thing, with its `imageSrc`
    return {
      id: file.id,
      fileSrc
    };

  }


};
Jarrod
@nahanil
@Chatto You gotta define the upload in the files array and the inputs dictionary.
files: ['image'],
inputs: {
  image: { type: 'ref' },
  ...otherInputs
}
Jarrod
@nahanil
@Noitidart does an array work with the email validator? Anchor gives us isEmail: true I think - not sure how you could say you want an array of email addresses (short of using a "custom validator function" thingy)
Robertino Vasilescu
@Rho-bur
@svenvarkel Thank you for pointer! Although I am using an ec2 instance and can of course create an S3 bucket, I am not familiar with CloudFront Distribution. A problem with saving the links in the DB may be the fact that I am going to use a lot of image variants, default, medium, small, thickbox like, thumbnails... I'll probably need a few linked tables for that and I wonder if it is not an overkill. What do you think?
Noitidart
@Noitidart
@nahanil will test out!
Noitidart
@Noitidart
OOo @nahanil I tested it out. And if we have an schema for the type, we can't use isEmail! it gives this error:
error: The action `ads/create-ad` could not be registered.  It looks like a machine definition (actions2), but it could not be used to build an action.
Details: ImplementationError: Sorry, could not interpret "ads/create-ad.js" because its underlying implementation has a problem:
------------------------------------------------------
• Invalid input definition ("offers").  Cannot use `isEmail` with that type of input.
Websirs
@websirs
hello!
finally deployed the app on heroku
and after dealing with issues with css files not loading, due to grunt not loading automatically, due to manually deploying through git instead of github auto deploy
there is a new issue -- with POST/PUT/action requests returning 403 forbidden
it was working before and suddenly when i changed domain to live, from the heroku staging url... it stopped working
sockets onlyallow origin url updated
baseurl updated
Websirs
@websirs
the difference between it working and not working
  • using custom domain, vs using heroku subdomain
  • using cloudflare with ssl on the custom domain
let me try without ssl
only works with the heroku subdomain
custom domain returns 403 on all put/post and similar requests (to do an action)
Websirs
@websirs
i thought it was cors allowOrigins
added the domain on it, didnt work
i thought it was the security.js cors allow origins settings, it didnt work
Websirs
@websirs
its the csrf protection
when i set it to false, it works
but now there is a new problem, the submit buttons work but it wont login
so the login doesnt persist
Noitidart
@Noitidart
@websirs try reading this article i wrote, its for digitalocean but it should help - https://medium.com/@Noitidart/deploying-sails-app-to-digital-ocean-droplet-with-https-445b3bac695d
RSA
@aflatoon2874
Is there a method available in sails to get the express application instance? I know it is available as sails.hooks.http.app but referencing it directly is not advisable. A method call would be better, for example sails.getExpressApplication()
Noitidart
@Noitidart
what are the risks of referencing directly?
just asking for learning. i dont know if ill ever access express
Chatto von Terpa
@Chatto
Hello Everyone!
amaljm
@amaljm
Hi, in VS code, the goto definition is not working and I cannot find an extension for this feature. Any work arounds for this?
Chatto von Terpa
@Chatto
How do I check if an item already exist in the db?
if (await ForumCategories.find({name:inputs.name})){
      throw 'exists';
    }
this throws an error no matter what it seems
amaljm
@amaljm
You can use .count to get count of the rows from table