Giter Site home page Giter Site logo

netlify-local's Introduction

Netlify Local

Travis CI badge Codeclimate maintainability Dependabot Status

Local Netlify service emulation.

Experimental: This package has not been heavily tested or used, some of the Netlify Services are incorrectly implemented. Submit an issue if you find any!

Semver Notice: Breaking changes which increase compatibility with Netlify services and features are not considered breaking ๐Ÿคทโ€โ™‚๏ธ

For help bundling your Javascript to work with Netlify Functions, checkout netlify/netlify-lambda or 8eecf0d2/webpack-netlify-lambda-plugin.

An example Netlify deployable application is available at 8eecf0d2/netlify-local-example.

Install

You should probably install as a dev dependency, but globally works too.

yarn add -D netlify-local

Usage

Currently netlify-local only provides a serve command.

netlify-local serve <options>

For a detailed list of options see the wiki.

Features

Static Router

The static router refers to the static server functionality of Netlify Continuous Deployment, which serves files from the build.publish directory, specified within the toml configuration.

Lambda Router

The lambda router refers to the Netlify Functions feature which serves Lambda's or Cloud Functions from the build.functions directory, specified within the toml configuration.

Redirects

This feature refers to Netlify Redirects, this has not been correctly implemented and is missing a lot of functionality, see Issue #8 for progress.

Headers

This feature refers to Netlify Headers, for the most part this works as expected however the Netlify Basic Auth portion is not supported.

API

Specific classes and methods are exposed for running netlify-local programmatically, see Issue #6 for more information and documentation.

Typings

Relevant Typescript typings are exposed for the API and also Netlify Function handlers.

import { Netlify } from "netlify-local";

export const handler: Netlify.Handler<handler.Request, handler.Context, handler.Response> = (request, context, callback) => {

  return callback(null, {
    statusCode: 200,
    body: "foo"
  })
}

export namespace handler {
  export interface Request extends Netlify.Handler.Request {
    headers: {
      example: string;
    }
  }
  export interface Context extends Netlify.Handler.Context {
    user: { ... }
  }
  export interface Response extends Netlify.Handler.Response {
    body: { ... };
  }
}

Webpack

Multiple Configs

If you use multiple Webpack configurations for your application (one for the client, another for lambda) you should set the name property within the Webpack configuration to get better logging, otherwise config's will be named by their index.

Issues

To correctly execute lambda's they must be self contained bundles, a common issue when bundled incorrectly is missing modules similar to the error below.

Error: Cannot find module '/.../path/file'

To bundle your files correctly ensure that module.exports.handler is exposed for each handler file and that you're using individual entires within webpack.

module.exports = {
  target: "node",
  entry: {
    foo: "./src/ts/handlers/foo.ts",
    bar: "./src/ts/handlers/bar.ts",
    ...
  },
  ...
}

If you're starting a new project or not currently bundling, the easiest solution would be to use netlify/netlify-lambda and it's build command.

If you've got a pre-existing webpack config I'd suggest using a webpack helper library such as 8eecf0d2/webpack-netlify-lambda-plugin.

Credit

This project is inspired by netlify/netlify-lambda.

netlify-local's People

Contributors

8eecf0d2 avatar dependabot-support avatar greenkeeper[bot] avatar

Watchers

John Vandenberg avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.