Before it makes sense to start a project, please make sure you have the following installed on your machine:
See Vapor docs for information on how to set it up. During the beta of Vapor Cloud, you might want to install the beta version of the CLI instead - for more information about this, see the Vapor Cloud docs.
For projects using a database, MySQL needs to be installed. This can be done through brew, e.g. brew install mysql
. See this guide for more information.
For projects using Redis as a cache, make sure to install this using brew by calling brew install redis
. See this guide for more information.
Our Vapor template comes with some convenient packages which are used in most of our projects. Remember to look at the documentation for the template for further instructions on how to get it up and running.
vapor new my-project-name --template=https://github.com/nodes-vapor/template
After you've aligned the project name with your project team, you can create the repo on the nodes-projects organization. Check this guide (internal) for information on naming of repos.
If you're setting up a customer project, then go ahead and delete the LICENSE
file. If it's an open source project, then keep the MIT license file but make sure to update any year references if needed.
Have a look at this template (internal) for setting up your README
file for customer projects. Towards the top of the file, make sure to add the relevant badges. It should look something like:
[Swift version] [Vapor version]
`master`: [Circle CI] [Codebeat]
`develop`: [Circle CI] [Codebeat]
See some of the other projects on the nodes-projects organization for comparison and check out the Circle CI and Codebeat sections below for information on how to generate the badges.
After the repository has been created and Circle CI (see Circle CI section) has been set up, go to the "Settings" part of the repository on Github and hit "Branches". In here you want to make sure that develop
is set as the default branch and that master
and develop
are added as protected branches. For each protected branch make sure that the following options are checked:
- "Protect this branch"
- "Require status checks to pass before merging"
- "Require branches to be up to date before merging"
- "ci/circleci: Linux"
- "ci/circleci: MacOS" (if running Vapor 2 or newer)
After the repository has been created on GitHub, the project can be added to Circle CI. Make sure you're on the nodes-projects organization (on Circle CI), hit "Add Projects". On the following page search for your repository name and hit "Set Up Project". On the next page choose "Linux" under "Operating "System" and hit "Start building" at the bottom of the site.
Last step is to generate a token for the Circle CI badge for the readme. Select your newly created project on Circle CI and hit settings (the gear icon), go to "API Permissions" and hit "Create Token". Choose "Status" as scope and write "Badge" as the token label. This generated token can now then be used for the Circle CI badge for the readme by inserting it into the url at the right spot:
[![Circle CI](https://circleci.com/gh/nodes-projects/my-project/tree/master.svg?style=shield&circle-token=my-token)](https://circleci.com/gh/nodes-projects/my-project)
Note that in order to create the badge for the develop environment you first have to trigger a Circle CI build on develop by pushing a commit.
We use Codebeat for static code analysis. Although the reports and the GPA score should be taken with a grain of salt, the reports are still useful for getting recommendations for areas to improve in the codebase. Each repository and branch needs to be set up manually. After logging into Codebeat (please reach out to a fellow developer for credentials) you can add the master
and develop
branches for the repository. When Codebeat is done analyzing, the badges for the readme will be available under "Settings" within the different reports.
Using the Vapor Cloud CLI, your Vapor project can be deployed to the cloud. See the Vapor Cloud docs for more information on how to do this.
If the API is going to be used in a web app, consider adding the CORS middleware.
let corsConfiguration = CORSConfiguration(
allowedOrigin: .all,
allowedMethods: [.get, .post, .put, .options, .delete, .patch],
allowedHeaders: ["Accept", "Authorization", "Content-Type", "Origin", "X-Requested-With", "N-Meta"]
)
drop.middleware.insert(CORSMiddleware(configuration: corsConfiguration), at: 0)
Read more: https://github.com/vapor/documentation/blob/master/http/cors.md
Test: http://codepen.io/dennishn/pen/BLbYyJ
If you need to store files, e.g. images, the Storage package is here to help you.