Sails.js Tutorial EP2

Source: Internet
Author: User
Tags key string

Here are a few basic file configurations

1

Config/local.js

This file is a local environment configuration

Configuration of the Config/local.js:

Port:process.env.PORT | | 1339, Environment:process.env.NODE_ENV | | ' Development ',//The runtime "Environment" of your Sails app is either ' development ' or ' production '.

The first is the port on which the project is run

The second one is the run mode

In the development mode, the operation will have an error message, the release mode will ignore these

Detailed instructions in the bottom note of the Local.js

2

Config/adapters.js

Local Database Configuration

I'm using MySQL here.

module.exports.adapters = {    // if you leave the  Adapter config unspecified    // in a model definition,   ' Default '  will be used.    // persistent adapter for  DEVELOPMENT ONLY    //  (data is preserved when the  server shuts down)      ' default ':  ' MySQL ',     disk : {        module:  ' Sails-disk '     },     // mysql is the world ' s most popular relational  database.    // Learn more: http://en.wikipedia.org/wiki/MySQL     myLocalMySQLDatabase: {        module:  ' Sails-mysql ',         host:  ' your_mysql_server_hostname_or_ip_address ',         user:  ' Your_mysql_user ',         // psst.  You can put your password in config/local.js instead         // so you don ' t inadvertently push it  Up if you ' re using version control         password:  ' Your_mysql_password ',        database:  ' YOUR_ mysql_db '     },    mysql: {         module:  ' sails-mysql ',        host:  ' 127.0.0.1 ',         port: 3306,         user:  ' Root ',        password:  ' pwd ',         database:  ' dbname '     }    /*       OR  (explicit sets take precedence)      *//*module    :  ' sails-mysql ',     url      :  ' Mysql2://user:[email protected]:P ort/databasename ' *//*     }*/};

The MySQL configuration here is using the Sails-mysql component

This module is an extension from the waterline component

Of course, waterline doesn't need to be installed.

Just install Sails-mysql in the project folder first

CNPM Install Sails-mysql

3

Config/cors.js

Look at this name and you should know that cross-domain configuration

        //Configure cross-domain allroutes: true,// which domains for all routing links  which are allowed CORS access?// This can be a  comma-delimited list of hosts  (beginning with http:// or https://)//  or  "*"  to allow all domains cors access.//open cross-domain origin:  ' * for all IP addresses ',         //allows cookie domains to be passed across domains// allow cookies to be  shared for CORS requests?credentials: true,         //don't explain this,?// which methods should be allowed for cors . requests?  this is only used// in response to preflight  requests  (see article linked above for more info) methods:  ' GET,  Post, put, delete, optionS, head ',// which headers should be allowed for cors requests?   This is only used// in response to preflight  requests.headers:  ' Content-type '

4

Cross-Domain encryption

If an open project is required to be open to a third party, it needs to be encrypted.

There are also configurations for cross-domain encryption

Config/csrf.js

File contents

MODULE.EXPORTS.CSRF = false;

I'm not encrypted in this project, and I'm not open to it.

5

Session Configuration

Config/session.js

File contents

Secret: ' key string can be arbitrarily customized ', cookie: {maxage:4*60*60*1000//time length}

6

Routes Routing Configuration

Config/routes.js

The domain name that can customize the controller and the action function

' Message/inbox '://Of course this key can be customized by {controller: ' Messagecontroller ', Action: ' Inbox '}

So ... Just Jiangzi it ...

7

There is also a file that may not appear when the project is generated by default

Config/application.js

File contents

module.exports={port:1333, AppName: "title headline", Successre:{"code": "0", "MSG": "Success"}, errre:{"code": "043", "MSG": " "}};

For simple configuration like this, use the method:

Sails.config.appName This allows the entire project to be called globally.

Equivalent to a constant file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.