Learning VueJS 2.x

I. First project with node + vue

See more https://vuejs-templates.github.io/webpack/

II. Create fake json-server for develop

go to source folder

Install json-server

Create folder api in source folder

Create a

file

Start JSON Server

Now if you go to http://localhost:3000/posts/1, you’ll get

{ id: 1, title: json-server, author: typicode }

Add custom routes

Create a

file. Pay attention to start every route with

.

Start JSON Server with

option.

Now you can access resources using additional routes.

/api/posts # → /posts 
/api/posts/1  # → /posts/1 
/blog/posts/1/show # → /posts/1 
/blog/javascript # → /posts?category=javascript 

Add middlewares (handle request and response)

You can add your middlewares from the CLI using

option:

json-server db.json –middlewares ./hello.js

CLI usage

json-server [options] <source>
 
Options:
  –config, -c       Path to config file           [default: “json-server.json”]
  –port, -p         Set port                                    [default: 3000]
  –host, -H         Set host                               [default: “0.0.0.0”]
  –watch, -w        Watch file(s)                                     [boolean]
  –routes, -r       Path to routes file
  –middlewares, -m  Paths to middleware files                           [array]
  –static, -s       Set static files directory
  –read-only, –ro  Allow only GET requests                           [boolean]
  –no-cors, –nc    Disable Cross-Origin Resource Sharing             [boolean]
  –no-gzip, –ng    Disable GZIP Content-Encoding                     [boolean]
  –snapshots, -S    Set snapshots directory                      [default: “.”]
  –delay, -d        Add delay to responses (ms)
  –id, -i           Set database id property (e.g. _id)         [default: “id”]
  –quiet, -q        Suppress log messages from output                 [boolean]
  –help, -h         Show help                                         [boolean]
  –version, -v      Show version number                               [boolean]
 
Examples:
  json-server db.json
  json-server file.js
  json-server http://example.com/db.json
You can also set options in a configuration file.

 

Leave a Reply

Your email address will not be published. Required fields are marked *