All Projects → zhex → fe-dev-server

zhex / fe-dev-server

Licence: MIT license
FE Dev Server target to help frontend web developers create view template, styles and js easily.

Programming Languages

javascript
184084 projects - #8 most used programming language
Handlebars
879 projects

Projects that are alternatives of or similar to fe-dev-server

factory
Generate lots of mock API data with ease.
Stars: ✭ 17 (-43.33%)
Mutual labels:  mock, mock-data
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+11393.33%)
Mutual labels:  mock, mock-data
better-mock
Forked from Mockjs, Generate random data & Intercept ajax request. Support miniprogram.
Stars: ✭ 140 (+366.67%)
Mutual labels:  mock, mock-data
interface-forge
Graceful mock-data and fixtures generation using TypeScript
Stars: ✭ 58 (+93.33%)
Mutual labels:  mock, mock-data
mock-data
Mock data in PostgreSQL/Greenplum databases
Stars: ✭ 115 (+283.33%)
Mutual labels:  mock, mock-data
miz
🎯 Generate fake data, Just like a person.
Stars: ✭ 24 (-20%)
Mutual labels:  mock, mock-data
ng-apimock
Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
Stars: ✭ 102 (+240%)
Mutual labels:  mock, mock-data
Shallow Render
Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
Stars: ✭ 242 (+706.67%)
Mutual labels:  mock
go-github-mock
A library to aid unittesting code that uses Golang's Github SDK
Stars: ✭ 63 (+110%)
Mutual labels:  mock
Okhttp Json Mock
Mock your datas for Okhttp and Retrofit in json format in just a few moves
Stars: ✭ 231 (+670%)
Mutual labels:  mock
Axios Mock Adapter
Axios adapter that allows to easily mock requests
Stars: ✭ 2,832 (+9340%)
Mutual labels:  mock
openman
Postman to OpenAPI Spec converter with mocking and documentation
Stars: ✭ 17 (-43.33%)
Mutual labels:  mock
walletconnect-test-wallet
Test Wallet (Web)
Stars: ✭ 163 (+443.33%)
Mutual labels:  mock
HttpClientMock
Library for mocking Apache HttpClient.
Stars: ✭ 41 (+36.67%)
Mutual labels:  mock
Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (+743.33%)
Mutual labels:  mock
Faker
Provides fake data to your Android apps :)
Stars: ✭ 234 (+680%)
Mutual labels:  mock
mocka
Mocka - The complete testing framework for LUA and Nginx
Stars: ✭ 26 (-13.33%)
Mutual labels:  mock
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (+670%)
Mutual labels:  mock
Mujina
A mock IDP and SP using the OpenSAML library
Stars: ✭ 250 (+733.33%)
Mutual labels:  mock
xrm-mock-generator
📖  Generates a mock Xrm.Page object. Commonly used by xrm-mock to test Dynamics 365 client-side customisations.
Stars: ✭ 15 (-50%)
Mutual labels:  mock

FE Dev Server Build and Deploy

FE Dev Server target to help frontend web developers create view template, styles and js easily. It try the best to simulate real server environment which can help you to make you job done.

Features

  1. Various template engines and embedded page data.
  2. Url simulation
  3. Mock data in file
  4. Proxy configuration

Quick start

Install it as a command line tool with the following step:

Install module globally

$ npm install -g fe-dev-server

create project folder and get into the folder

$ mkdir workdir && cd workdir

initial the project folder

$ fds init

start up server

$ fds server

start up server & open browser

$ fds server -o

Also, it can be integrated into your own project as a node module.

var fds = require('fe-dev-server');

var app = fds({
    basePath: __dirname,
    mockFolder: 'data',
    port: 8001  
});

Routes

Routes is stored in routes.js as key/value pairs by default.

Sample:

module.exports = {
    // set /test route to test.html page, default http method is GET
    '/test':                    'test.html',
    
    // set /books route to books.pug template with GET method
    'GET::/books':              'books.pug',
    
    // set json api with a json file in mock folder
    'POST::/api/books':         'mock::books.json',
    
    // mock file can also be a js file, which has more power to do the customization
    'GET::/api/category':       'mock::category.js',

    // fds works with java template such as jsp;
    // before do this, you have to set enableJava to true in your fds-config.js file
    '/jsp-page':                'books.jsp',
    
    // it allow your route to proxy an online page
    '/proxy-api':               'http://www.github.com/zhex.json',
    
    // proxy can do fuzzy mapping;
    // in the setting, if you visit /books/hello, it will map to http://example.com/books/hello
    'ALL::/books/:pattern*':    'http://example.com/books/'
};

the rule is '[method]::[route_url]': '[template_file]'.

Allowed method: GET, POST, PUT, PATCH, DETELE

GET will be used if it is not specified.

If you want to setup an ajax api url, you can set the template to a json file. The server will look for the json/js file in view folder and send back it as a json object. the data in the view folder sounds not make sense. So if you want put the json/js file in the mock folder, then you can add a mock:: prefix in the template path, then the server will look for the file in mock folder.

If the mock file is a js file, then it is good to define as a module function:

module.exports = function (data, utils) {
    return {
        id: data.params.id,
        name: data.query.name || 'hello world',
        content: data.body.content
    };
};

The data.params is the match variable collection in the particular route; The data.query is the query data from request url, so you can easily test your page with different api return.

utils provide some easy to use method to handle the data.

available method:

  • utils.isObject(obj)
  • utils.isArray(obj)
  • utils.isFunc(obj)
  • utils.contains(array, item)
  • utils.serialize(obj)
  • utils.assign() - which is object-assign library
  • utils.moment() - which is moment library
  • utils.Mock - which is mockjs library

Also, you can add $$header in the data file to extend http response header, and using $$delay to set simulate the http connection delay.

{
    "$$header": {
        "x-access-token": "abcs"
    },
    "$$delay": 3000,
    "title": "hello world"
}

embedded template engines

Configuration

You can custom your configuration in fds-config.js file.

defaultConfig = {
    basePath: path.resolve(__dirname, './example'),
    publicFolder: 'public',
    viewFolder: 'views',
    mockFolder: 'mocks',
    routeFile: 'routes.js',
    port: 3000
}

basePath

The base path of the project, all other folder settings are related to base path.

viewFolder

default: 'views'

Where you can put your view template files.

mockFolder

default: 'mocks'

Save you mock data into this folder. each view template will have a matched json data file will be loaded automatcially.

For example: we have a ${viewFolder}/projects/index.html template, then data in ${viewFolder}/projects/index.json file will be auto loaded into the template.

publicFolder

default: 'public'

Where you can put your image, style and js files here. This folder is set by express.static()

routeFile

default: 'routes.js'

Routes mapping file

mockExts

default: ['.js', '.json']

Some people like to set mockFolder as the same as viewFolder for convinence reason, mockExts give you the ability to define your own mock file type to avoid the conflict issue. Also, the ext order in array demonstrate the priority from higher to lower.

port

default: 3000

Express server port

enableJava

default: true

Sometimes you don't need to support java templates, you can turn it off with this property to false.

livereload

default: true

livereload is awesome, it will refresh your browser automatically after anything changed. If you dont like this feature, you can set it to false to switch it off. also you can set it as a livereload option object;

open

default: { route: '/', browser: ['google chrome'] }

Browser setting allow you to open dev site automatically on server started with -o option in cli. It will open google chrome by default.

$ fds server -o

License

This project is licensed under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].