Sunday, April 2, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home Swift

The anatomy of Vapor commands

learningcode_x1mckf by learningcode_x1mckf
September 23, 2022
in Swift
0
The anatomy of Vapor commands
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


2020/03/25

Learn to construct and run your present Vapor apps utilizing varied command line arguments, flags and environments.

Vapor

The Vapor toolbox

The very very first thing I need to present you (once more) is the Vapor toolbox command line utility. It is a good little handy software for initializing new Vapor purposes from scratch. You should use it to construct, run, replace, check and even deploy (to Heroku) your undertaking.


vapor new myProject
cd myProject
vapor construct
vapor run

Personally I am not utilizing it an excessive amount of, besides once I create a brand new undertaking. I would like to generate extra “boilerplate” code for controllers, fashions utilizing the toolbox, however sadly this function isn’t carried out but. The loopback-cli is a superb instance tho… 🙏

You’ll be able to run vapor --help to see all of the out there instructions.



Serve

Each server must hear for incoming requests on some port. The serve command begins the Vapor utility and fires up the HTTP server. You’ll be able to specify the hostname and the port utilizing some extra flags. The bind flag combines the hostname and port flags into one, they each have brief and lengthy variations, be at liberty to select your favourite command format. 😉


swift run Run


swift run Run serve
swift run Run serve --hostname "localhost" --port 8080
swift run Run serve -h "localhost" -p 8080
swift run Run serve --bind "localhost:8080"
swift run Run serve -b "localhost:8080"

You need to know that that is the default command, so if you happen to merely run your app with none arguments, the serve command will probably be executed behind the scenes. 💀



Migrate

Once you work with databases using Fluent, you want a schema first. You’ll be able to solely populate the database with precise information after the principle construction exists. This course of is named migration. You will additionally should migrate your database if you happen to change one thing in your Fluent code (for instance you introduce a brand new discipline for a mannequin). You’ll be able to carry out a migration by operating:


swift run Run migrate


swift run Run migrate --auto-migrate


swift run Run migrate --revert

The cli will present you what must be carried out with a view to hold your DB up-to-date. You’ll be able to double test every thing yet one more time earlier than you proceed, or you may skip the whole affirmation dialog by utilizing the --auto-migrate possibility. Be extraordinarily cautious with auto migrations! ⚠️



Log ranges

You may need seen that there are a bunch of Vapor messages in your console. Nicely, the excellent news is that you would be able to filter them by log stage. There are two methods of doing this. The primary possibility is to supply a log flag with one of many following values:

  • hint
  • debug
  • information
  • discover
  • warning
  • error
  • important

The --log flag has no brief variant, do not attempt to use -l.

If you wish to hint, debug and information logs, you may run the app like this:


swift run Run --log discover


The second possibility is to set a LOG_LEVEL variable earlier than you run the app.


LOG_LEVEL=discover swift run Run


export LOG_LEVEL=discover
swift run Run

unset LOG_LEVEL

The exported variable will probably be round till you shut the terminal window otherwise you take away it.



Setting

Each Vapor utility can run in improvement or manufacturing mode. The default mode is improvement, however you may explicitly set this utilizing the command line:


DB_URL="postgres://myuser:[email protected]:5432/mydb"


swift run Run --env improvement
swift run Run -e dev


DB_URL="postgres://realuser:[email protected]:5432/realdb"


swift run Run --env manufacturing
swift run Run -e prod

It’s potential to retailer environmental variables in a dot env file. The .env.improvement file will probably be loeaded in improvement mode and the .env file in manufacturing mode. You may also use the .env.testing file for the check atmosphere.

You may also override environmental variables with a neighborhood variable, like the way in which we outlined the LOG_LEVEL earlier than. So as an example if in case you have a DB_URL in your manufacturing .env file, however you continue to need to use the dev database, you may run Vapor like this:

DB_URL="postgres://myuser:[email protected]:5432/mydb" swift run Run --env manufacturing

Setting variables are tremendous cool, it is best to mess around with them to get acquainted.



Routes

That is very helpful command to shortly show all of the related endpoints that your app has.


swift run Run routes











When you want extra information about how routing works in Vapor 4, it is best to test the official docs.



Boot

Actually: I’ve by no means used the boot command earlier than, however it’s there. ¯_(ツ)_/¯


swift run Run boot

Can any person inform me a use case for this?



Customized instructions

It’s potential to jot down your customized instructions using the brand new Command API in Vapor 4. In case you are excited by writing Swift scripts, it is best to proceed studying the linked article. 📚


There are many different Swift compiler flags (e.g. -Xswiftc -g to make Backtrace.print() work) that you should utilize throughout the construct course of. In case you are excited by these please let me know and perhaps I will make an article about it within the not so distant future.






Source link

You might also like

Swift Against Humanity – Hacking with Swift

Introducing MotionBar – the Animated Tab Bar Library

Introducing – AI Utils for macOS

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Swift Against Humanity – Hacking with Swift

by learningcode_x1mckf
April 1, 2023
0
Swift Against Humanity – Hacking with Swift

So that you suppose you already know Swift? Assume once more! Recent from the success of our audiobook launch, Laboratoires TwoStraws is again with an all-new card sport...

Read more

Introducing MotionBar – the Animated Tab Bar Library

by learningcode_x1mckf
March 31, 2023
0
Introducing MotionBar – the Animated Tab Bar Library

In an earlier tutorial, we shared find out how to create a customized tab bar view utilizing SwiftUI to exchange the usual tab bar. If you happen to’ve...

Read more

Introducing – AI Utils for macOS

by learningcode_x1mckf
March 24, 2023
0
Introducing – AI Utils for macOS

⚠️ REQUIRES a FREE OpenAI API key. You will get one utilizing this hyperlink. ⚠️ Improve your productiveness with our AI powered utility application. - accessible...

Read more

Encoding and decoding data using the Hummingbird framework

by learningcode_x1mckf
March 22, 2023
0
Encoding and decoding data using the Hummingbird framework

HTTP is all about sending and receiving information over the community. Initially it was solely utilized to switch HTML paperwork, however these days we use HTTP to switch...

Read more

Hummingbird routing and requests – The.Swift.Dev.

by learningcode_x1mckf
March 17, 2023
0
Hummingbird routing and requests – The.Swift.Dev.

Routing on the server facet means the server goes to ship a response primarily based on the URL path that the consumer referred to as when firing up...

Read more
Next Post
8 new JavaScript features to start using today

8 new JavaScript features to start using today

Leave a Reply Cancel reply

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

Related News

Oracle Releases GraalVM 22.3, GraalVM CE Java Code Going To OpenJDK

Oracle Releases GraalVM 22.3, GraalVM CE Java Code Going To OpenJDK

October 26, 2022
Java Developer – IT-Online

Java Developer – IT-Online

October 6, 2022
Dynamic routes and page hooks in Feather CMS on top of Vapor 4

Dynamic routes and page hooks in Feather CMS on top of Vapor 4

September 20, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • So why did they decide to call it Java? – InfoWorld
  • Senior Java Developer – IT-Online
  • 4 Packages for Working With Date and Time in JavaScript – MUO – MakeUseOf

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?