@0x4447/tomato 中文文档教程

发布于 6年前 浏览 22 项目主页 更新于 3年前

Tomato

Tomato 是我们对 ExpressJS 附带的 express-generator CLI 的看法。 我们创建这个项目是因为我们花了太多时间来加快默认的 ExpressJS 模板的速度,尤其是当我们不得不不断启动新的微服务时。

这个项目的一个很好的特点是它很容易定制。 如果您有自己的风格,只需克隆此 repo 并编辑 source 文件夹以满足您的需要。

How to install

] sudo npm install -g @0x4447/tomato

How to use

] tomato -d PATH_TO_FOLDER

Where to get help

] tomato -h

What to expect

source 文件夹中有两个模板,一个用于在 ExpressJS 中构建网站,另一个用于构建 API。 在这种情况下,API 模板是 Website 文件夹的精简版本 - 有一些小的变化。 您将在下面找到所有共享功能的列表,但不限于它们不共享的功能。

Shared key features

  • Our preferred personal commenting style
  • A simplified and thoroughly explained server file that immediately demonstrates what each line of code does
  • Clustering used by default
  • Redesigned handling and display of errors
  • Knex used by default to talk with the database
  • Code to start the server in workers folder since it's a worker and we always end up with more than the server
  • Everything organized in the way we like it :)

Website

  • Redirect to HTTPS in production
  • Compression used by default when sending requests
  • Hogan used by default for templating (nice and simple)
  • Favicon done right: Make five icons with Real Favicon Generator
  • Basic Open Graph support
  • Twitter Cards support

API

  • Throws error if there is no HTTPS in production
  • Removes the ETag from the header response
  • Removes the Data entry in the header response
  • Built-in check for an API Key

The entire flow to get the project up and running follows:

] sudo npm -g install @0x4447/tomato

一旦你在全局安装了这个 npm 包,你就可以在任何地方使用它。 转到您要在其中创建新项目的文件夹,然后:

] tomato -d PATH_TO_FOLDER

选择最适合您需要的选项,然后进入您刚刚创建的目录并键入:

] npm install

接下来,创建一个 .env 将环境变量加载到内存中的文件 - 感谢 foreman。 或者您可以按以下方式安装我们的另一个工具 env-auto

] npm install cucumber -g

在项目的根文件夹中,键入:

] cucumber -s PATH_TO_FOLDER

这会自动创建从 app.json 文件创建的 .env 文件。 最后一步是开始整个事情:

] npm start

WARNING

这个工具将覆盖、销毁、杀死和崩溃其路径中的所有内容。 你已被警告! ;)

Fork it

我们以如此简单的方式设计了这个项目,您可以将其制作成您自己的。 分叉后,只需更改 source 文件夹的内容,您就会拥有自己的易于使用的模板,并在需要时随时运行。

The End

如果您喜欢这个项目,请考虑给它一个????。 并查看我们的 0x4447 GitHub 帐户,其中包含您可能会觉得有用或有趣的其他资源。

该项目由 0x4447 LLC 提供,这是一家专门在 AWS 上构建自定义解决方案的软件公司。 点击此链接了解更多信息:https://0x4447.com。 或者,发送电子邮件至 hello@0x4447.email

???? Tomato

Tomato is our take on the express-generator CLI that comes with ExpressJS. We created the project because we were spending too much time on bringing the default ExpressJS template up to speed, especially when we had to constantly spin up new micro-services.

One nice feature of this project is that it's simple for you to customize. If you have your own style, just clone this repo and edit the source folder to suit your needs.

How to install

] sudo npm install -g @0x4447/tomato

How to use

] tomato -d PATH_TO_FOLDER

Where to get help

] tomato -h

What to expect

There are two templates in the source folder, one for building a Website in ExpressJS, and another for building an API. In this case, the API template is a stripped-down version of the Website folder - with some minor changes. Below you'll find the list of all the shared features, but not limited to features they don't share in common.

Shared key features

  • Our preferred personal commenting style
  • A simplified and thoroughly explained server file that immediately demonstrates what each line of code does
  • Clustering used by default
  • Redesigned handling and display of errors
  • Knex used by default to talk with the database
  • Code to start the server in workers folder since it's a worker and we always end up with more than the server
  • Everything organized in the way we like it :)

Website

  • Redirect to HTTPS in production
  • Compression used by default when sending requests
  • Hogan used by default for templating (nice and simple)
  • Favicon done right: Make five icons with Real Favicon Generator
  • Basic Open Graph support
  • Twitter Cards support

API

  • Throws error if there is no HTTPS in production
  • Removes the ETag from the header response
  • Removes the Data entry in the header response
  • Built-in check for an API Key

The entire flow to get the project up and running follows:

] sudo npm -g install @0x4447/tomato

Once you have this npm package installed globally, you can use it anywhere. Go to a folder in which you'd like to create a new project, then:

] tomato -d PATH_TO_FOLDER

Select the option that best suits your needs, then go into the directory you just created and type:

] npm install

Next, create a .env file to load your environment variables into memory - thanks to foreman. Or you can install another of our tool, env-auto in this manner:

] npm install cucumber -g

In your project's root folder, type:

] cucumber -s PATH_TO_FOLDER

This automatically creates the .env file created from the app.json file. The last step is to start the whole thing with:

] npm start

WARNING

This tool will override, destroy, kill, and crash everything in its path. You've been warned! ;)

Fork it

We designed this project in such a simple way that you can make it your own. Once forked, just change the content of the source folder, and you'll have your own easy-to-use template up and running whenever you need it.

The End

If you enjoyed this project, please consider giving it a ????. And check out our 0x4447 GitHub account, which contains additional resources you might find useful or interesting.

This project is brought to you by 0x4447 LLC, a software company specializing in building custom solutions on top of AWS. Follow this link to learn more: https://0x4447.com. Alternatively, send an email to hello@0x4447.email.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文