Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
James Allenby
JAMP
Commits
a08fedc6
Commit
a08fedc6
authored
Feb 19, 2019
by
James Allenby
Browse files
Updated main.cc to provide better example
parent
7d1537b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
23 deletions
+7
-23
main.cc
main.cc
+7
-23
No files found.
main.cc
View file @
a08fedc6
#include <fstream>
#include "jampserver.hh"
std
::
string
get_file_contents
(
const
char
*
filename
)
{
std
::
ifstream
in
(
filename
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
in
)
{
std
::
string
contents
;
in
.
seekg
(
0
,
std
::
ios
::
end
);
contents
.
resize
(
in
.
tellg
());
in
.
seekg
(
0
,
std
::
ios
::
beg
);
in
.
read
(
&
contents
[
0
],
contents
.
size
());
in
.
close
();
return
(
contents
);
}
throw
(
errno
);
}
int
main
()
{
std
::
string
file
=
get_file_contents
(
"rules.ninja"
);
// Create a JAMP server object
JAMP
::
Server
server
;
// Register all URIs that you may want to use
server
.
All
(
"/"
,
[](
auto
&
request
,
auto
&
response
)
{
response
.
SetResponseCode
(
JAMP
::
Code
::
HTTP_200
);
response
.
Write
(
"
hello
"
);
response
.
Write
(
"
Hey there! Welcome to JAMP.
"
);
response
.
Close
();
});
server
.
All
(
"/rules"
,
[
file
](
auto
&
request
,
auto
&
response
)
{
// Register particular URIs on different paths
server
.
All
(
"/rules"
,
[](
auto
&
request
,
auto
&
response
)
{
response
.
SetResponseCode
(
JAMP
::
Code
::
HTTP_200
);
response
.
Write
(
file
);
response
.
Write
(
"These are the rules... don't break them."
);
response
.
Close
();
});
// Start the server finally
server
.
Start
(
10000
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment