4nth0 / golem Goto Github PK
View Code? Open in Web Editor NEWFrom a single config file Golem start a mock server
License: MIT License
From a single config file Golem start a mock server
License: MIT License
Currently, Golem isn't able to handle CORS headers for the preflight request.
Preflight requests use the OPTIONS method to validate the ability of the third-party domain to fetch data.
CORS can be handled by service or by path.
By Service
port: "7171"
services:
- name: "Ping Server"
http_config:
cors:
origin: "*" | "${request.host}" | "https://mywebsite.com"
methods: GET
routes:
"/ping":
body: '{"message": "pong!"}'
By Path
port: "7171"
services:
- name: "Ping Server"
http_config:
routes:
cors:
origin: "*" | "${request.host}" | "https://mywebsite.com"
methods: GET
"/ping":
body: '{"message": "pong!"}'
Currently, there is no way to have multiple methods for the same path.
Routes are declared with the following format :
routes:
"/foo":
body: "bar"
By default, the GET
method is used.
Here the way to set the method :
routes:
"/foo":
method: "POST"
body: "bar"
To handle multiple methods for the same route it can be interesting to use the following declaration format :
routes:
"/foo":
methods:
"GET"
body: "bar from get method"
"POST"
body: "bar from post method"
Golem is able to send pre-defined mocks but is unable to generate automatic mocks.
With the help of Faker solutions such as https://github.com/brianvoe/gofakeit Golem should generate mocks on the fly depending on YAML declaration of the expected mock scheme :
port: "8181"
services:
- name: "Autogen Mocks"
http_config:
routes:
"/posts":
generate:
scheme:
"title":
type: LoremIpsumSentence
word_count: 3
"content":
type: LoremIpsumParagraph
word_count: 3
"views":
type: Number
min: 0
max: 99
"published":
type: boolean
Afin de mieux intégrer golem dans la stack des différents projets, il pourrait être utile de le dockeriser et de le rendre disponible sur Dockerhub. Cela permettrait par exemple d'appeler directement l'image Docker de golem dans un docker-compose pour mocker les projets en local.
Yaml is a great format for local use.
For server use it can be easier to connect Golem to a database (PG, MySQL, ..)
Golem send the wrong status code when we call it with an unallowed HTTP method
port: "8989"
services:
- name: "Service Sample"
http_config:
routes:
"/foo":
body: "bar"
If I try to call the service with an unallowed method I have a 200 Ok
status code instead of 405 Method Not Allowed
curl -X POST http://127.0.0.1:8989/foo
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8989 (#0)
> POST /foo HTTP/1.1
> Host: 127.0.0.1:8989
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 25 Jun 2021 14:24:35 GMT
< Content-Length: 2
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host 127.0.0.1 left intact
Io* Closing connection 0
to know which version of Golam we are using
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.