Questions tagged [vapor]
A web framework and server for Swift that works on macOS and Linux.
813
questions
1
vote
1
answer
16
views
Vapor 4 Unable to Update Optional Parent with Put HTPP Request
I have a model called jurisdictions that houses political jurisdictions. Now theres jurisdictions can sit within other jurisdictions, so I have an optional parent jurisdiction...
Now I can create new ...
0
votes
0
answers
16
views
Running NSApplication.shared alongside Vapor?
I want my Vapor app to be able to create and show NSWindows on the host machine. For this I've edited main.swift like this:
import AppKit
import App
import Vapor
var env = try Environment.detect()
...
0
votes
0
answers
19
views
Query with Vapor/Fluent for nested one to many relationships
I have the following relations:
A container can have many question entities and a question entity can have many answers. In the Vapor/Fluent documentation I can only find examples with Parent and ...
1
vote
2
answers
43
views
PostgreSQL DB location query with Fluent 4
I have an application that stores items with a latitude and longitude, I wanted to create a query that filters the items and paginates them by their distance to a given lat/lon pair.
I have read ...
2
votes
1
answer
62
views
Vapor Swift How to Configure Client Connection Timeout
I am using Vapor Swift to send GET / POST requests from the server-side using the below methods:
req.application.client.get(<#T##url: URI##URI#>, headers: <#T##HTTPHeaders#>, beforeSend: &...
1
vote
2
answers
96
views
Is it possible to work with different schemas in Fluent with PostgreSQL?
I need to create tables with different number of fields for different users. I want to create a schema for each user, and in it a custom set of tables. I can do this with direct database queries. This ...
2
votes
1
answer
67
views
Vapor Server of Heroku Crashes: Possible Postgres Library Issue?
I'm putting this new information first: the problem that brought me to this point is below.
This is what I get once my app deploys to Heroku: seems to compile fine, though there is the issue described ...
2
votes
1
answer
41
views
Vapor, fluent save/create complex model with PostgreSQL
I'm trying to save model to PostgreSQL DB. The problem is, I can't properly save submodels.
When I save model, it saves only ID without any relation. What am I do wrong?
Request body are properly set ...
2
votes
1
answer
40
views
Vapor - fluent, save object to PostgreSQL
Could someone give me example please, how to save Object to DB?
For example, I am using a GET request which triggers the HTML parser and returns user a model. How I can save that model to my DB?
func ...
2
votes
1
answer
39
views
Find all items with empty many to many relationship in vapor fluent
Given the example from the vapor docs:
// Example of a pivot model.
final class PlanetTag: Model {
static let schema = "planet+tag"
@ID(key: .id)
var id: UUID?
@Parent(key: ...
1
vote
1
answer
92
views
Change Swift Version Project is Built With
I'm using Vapor, and I've run into a problem where the change to Xcode 13.3 from 13.1 now means the project (without changes) will no longer build.
How can I change the version of Swift that a Vapor ...
2
votes
1
answer
214
views
CircularBuffer error after upgrading to Xcode 13.3, SwiftNIO, Vapor in the mix
I have a project that will not compile, after upgrading to Xcode 13.3 The error is
Type 'CircularBuffer<Element>' does not conform to protocol 'MutableCollection'
and
Unavailable subscript '...
1
vote
1
answer
37
views
Manipulating .filter List in Vapor Fluent Query
When you construct a query using Fluent in Vapor, can the list of .filter (or .sort, etc.) be manipulated? For example, before executing the query, can I add, remove of change those components?
1
vote
2
answers
65
views
Remove time from ISO date to filter with Vapor Swift
I'm trying to figure out how to filter ISO dates. I'd like to filter out Todo's for a specific day.
Dates are save in the database like this:
"started" -> 2022-03-17 18:46:44+00
I'd like ...
2
votes
0
answers
64
views
Composing property wrappers in Swift with Vapor + Fluent
I've implemented a system to automatically generate Fluent's Migrations by reflecting 'registered' Models, saving the boilerplate of creating them manually. To achieve this, I must allow the ...
1
vote
1
answer
55
views
Can I give back nil instead of a tuple?
My first version of code worked well:
return Question.find(o.questionId, on: req.db).map { q in
guard let q = q else {
return nil
}
return GetUserQuestionsOut(text: q.text, questionId: ...
1
vote
1
answer
41
views
getting multiple average columns in vapor 4 fluent
I am working on a project in vapor and I would like to calculate the average of multiple columns,
but I can't figure out how to do it. I can get the average of one column like this:
let runCount = try ...
0
votes
0
answers
121
views
CORS error: Provisional headers are shown
My Backend runs in Heroku, frontend, Create React App in Vercel. I try bring them under the same domain name as docs says here:
https://vercel.com/support/articles/pointing-subdomains-to-external-...
0
votes
0
answers
36
views
Why Set-Cookie is not stored?
I have following HTTP response:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: accept, authorization, content-type, origin, x-requested-with, user-agent, access-control-allow-...
1
vote
0
answers
24
views
How to use regexp in Vapor Fluent sqlite?
I have a simple model that has a string field, like this:
final class Record: Model, Content {
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
...
...
1
vote
0
answers
32
views
Deploying a pre-compiled Vapor service
Our team has a Vapor service that we deploy on a Mac through an NGINX reverse proxy. It works as expected.
The problem is, every time we deploy a new instance via sudo swift run, Vapor compiles the ...
1
vote
1
answer
50
views
Vapor (SwiftNIO) Interfacing with Async Methods
I am trying to use an async method from a 3rd party library to get a string result from a URL
public static func fetch(url: URL, completion: @escaping (Result<String, Error>) -> Void) {
...
-1
votes
2
answers
48
views
How can be transformed [EventLoopFuture<Type>] into EventLoopFuture<[Type]> in Vapor?
I try to transform [EventLoopFuture Type ] into EventLoopFuture<[Type]>.
Code example:
struct QuestionDTO2: Content {
var text: String?
}
func getUserQuestions(req: Request) throws -> ...
1
vote
0
answers
101
views
How do I point a subdomain to a service outside of Vercel?
Following this tutorial: https://vercel.com/support/articles/pointing-subdomains-to-external-services
There are two things here: set A record and CNAME record in Vercel. Should I set both?
If so how ...
1
vote
0
answers
45
views
Why cookie is not set?
Do you have any idea why cookie is not set in client? It is sent from backend:
func loginEmail(_ req: Request) throws -> Response
{
let response = Response(status: .ok)
let cookie = ...
1
vote
1
answer
83
views
Querying nested children in Vapor's Fluent
Env: Vapor/Fluent 4.0.0
I have a tree structured data with model like this:
final class Ingredient: Model {
static let schema = "ingredients"
@ID(key: "id")
var id: ...
1
vote
1
answer
75
views
Deploying vapor on Heroku using Docker fails on $PORT
I'm trying to deploy my Vapor server side app to Heroku using Docker (I know it is possible to deploy using Git, but I want to learn more about Docker).
According to Heroku, the port to use is dynamic ...
2
votes
2
answers
227
views
Vapor: sending post requests
I am trying to send an HTTP request using Vapor, to verify a recaptcha
Google's Captcha api is defined as follows:
URL: https://www.google.com/recaptcha/api/siteverify METHOD: POST
POST Parameter
...
1
vote
0
answers
43
views
How to set CNAME to reach externel backend service?
Got an error here when press Login button: https://sp-poc.com/admin
Access to XMLHttpRequest at 'https://speechifai-poc.herokuapp.com/api/loginEmail' from origin 'https://sp-poc.com' has been blocked ...
1
vote
1
answer
101
views
Signing algorithm error while creating a jwt signer
I'm using Vapor jwt package and I'm getting such kind of error while creating a private jwt signer:
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: JWTKit error: signing algorithm ...
1
vote
1
answer
79
views
PostgreSQL DB query with Fluent 4
A Fluent Data query with the function below works:
func indexHandler(_ req: Request) -> EventLoopFuture<[CustomerWithOrders]> {
Customer
.query(on: req.db)
.with(\.$orders)...
1
vote
0
answers
101
views
How to set up a Binance WebSocket Connection with Vapor?
I tried setup Binance websocket like this, what do I miss?
app.get("hello") { req -> EventLoopFuture<String> in
return WebSocket.connect(to: "wss://stream.binance.com:9443&...
2
votes
1
answer
89
views
Deploying a Vapor app to Heroku fails because of " error: value of type 'URLSession' has no member 'data' "
I have created an application using Vapor and I want to deploy it to Heroku, but the push fails.
The build configuration looks like this
.swift-version: 5.5
use heroku-buildpack
The log looks like ...
1
vote
1
answer
203
views
Swift Vapor 4 upload , validate , resize an image file
I am trying to post a photo to the vapor 4 server.
I am sending a Team name as a string and an image as data.
struct SendTeam: Content {
var name: String
var img: Data
}
I want to upload the ...
1
vote
1
answer
40
views
How to properly query Postgres JSONB field in Vapor/Fluent
I have a table with some jsonb columns created by a migration like this:
public func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema(MyTable....
2
votes
0
answers
66
views
Lost requests body in Swift/Vapor http server [closed]
I have a pretty standard Vapor http server, It has a middleware where it inspects the request body and does some authentication validation.
func respond(to request: Request, chainingTo next: Responder)...
1
vote
1
answer
3k
views
Access to XMLHttpRequest has been blocked by CORS
I use Vapor for backend and Next.js for front end on Ubuntu and want to access database this way:
let cq = {
text: "My question",
};
axios({
method: "post",...
1
vote
1
answer
151
views
Vapor Fluent How to add a new required field key to existing table
I have a deployed backend built with Vapor Fluent PostgreSQL.
Now I need to add a new required field key new_field to the table with schema name schema_name in the database.
I created a new ...
1
vote
1
answer
79
views
how to add a new dependency to vapor?
I want to add a new dependency to vapor, but this error comes out - unknown package 'Web3' in dependencies of target 'App'; valid packages are: 'vapor', 'fluent', 'fluent-postgres-driver', 'jwt', '...
0
votes
2
answers
151
views
Why is my database not being cleared after each unit test?
I am trying to run a tests when no user is created and one can sign up for the first time. The test runs perfectly the first time and passes. The thing is that if I run it a second time, my container ...
1
vote
1
answer
72
views
Which Framework/Package to use for Swift Linux that also can be used for Vapor [closed]
I've written an API-Wrapper for an external REST-API. This wrapper provides iOS and macOS-Apps an convenient access to that API.
But I want to expand that API-Wrapper to Vapor on Linux.
Linux (RaspiOS ...
1
vote
0
answers
19
views
Why sending 'true' not helps? The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'
Got this error:
The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.
Here when pressing Login ...
1
vote
1
answer
48
views
How to unit test Vapor DB Objects
I have the following simple object relationship:
public final class Planet: Model {
@ID(key: .id)
public var id: UUID?
@Parent(key: .starId)
public var star: Star
It all ...
1
vote
0
answers
56
views
How do I fix the error while building the Vapor app?
When I create my project, everything looks good, vapor tells me "Project demoNew has been created!", but after that I try to build it and i have an error
Error looks like:
error: Error ...
1
vote
2
answers
157
views
Swift / SwiftNIO / Vapor: wait() or similar inside EventLoop & equivalent to JavaScript‘s Promise.all()
I‘m starting with Vapor 4 and got stuck at the very beginning of my journey.
I know Promises in JavaScript and I think I have an understanding of Swift‘s Futures. I think my problem is the fact, that ...
2
votes
1
answer
86
views
How and where to Install SSL certificate on vapor 4 app?
I am trying to deploy postgres in Digital Ocean. After setting up the Managed databases, it provided ca-certificate.crt which needs to be installed on the backend app.
Tech stack
Vapor for backend ...
1
vote
1
answer
121
views
How to read html files on Vapor with Leaf when not using the tau version?
There was a version of Leaf that I was using to load .html files instead of .leaf ones from my Vapor project, which would make syntax coloring for those same files done automatically.
The version of ...
1
vote
1
answer
110
views
Postgres jsonb data in Swift/Vapor
I have the following Vapor Fluent migration that creates a jsonb column
public func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema(MyModel.schema)
...
1
vote
1
answer
60
views
Database seeding and Eager Loading in Vapor
This is my code to perform database seeding:
func prepare(on database: Database) -> EventLoopFuture<Void> {
var citySaveResults: [EventLoopFuture<Void>] = []
...
1
vote
0
answers
60
views
Fatal error: No default database configured
When I try to do a migration of my database in heroku using vapor I get the following error when I run heroku run Run -- migrate --env production
FluentKit/Databases.swift:160: Fatal error: No default ...