-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 (codon/) Added a experiment of server to use codon
- Loading branch information
Showing
11 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
char* greet(char* name) { | ||
char* result = malloc(strlen(name) + 5); | ||
sprintf(result, "Hi! %s!", name); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def greet(name: str) -> str: | ||
return f"Hi {name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import http.server | ||
import socketserver | ||
|
||
with socketserver.TCPServer( | ||
("127.0.0.1", 8000), http.server.SimpleHTTPRequestHandler | ||
) as httpd: | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[tool.poetry] | ||
name = "codon" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Comamoca <[email protected]>"] | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "Comamoca" | ||
description = "A new awesome nimble package" | ||
license = "MIT" | ||
srcDir = "src" | ||
bin = @["server"] | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 1.6.10" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
proc greet*(name: cstring): cstring {.exportc.} = | ||
return "Hi! " & "{name}!" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asynchttpserver, asyncdispatch, strutils | ||
|
||
const HTML = {"Content-type": "text/html; charset=utf-8"} | ||
const JSON = {"Content-type": "application/json; charset=utf-8"} | ||
|
||
proc responce(req: Request, code: HttpCode, content: string, | ||
header: auto = HTML) {.async.} = | ||
await req.respond(code, content, header.newHttpHeaders()) | ||
|
||
proc run*(port: int, content: string) {.async dynlib exportc.} = | ||
var server = newAsyncHttpServer() | ||
|
||
proc cb(req: Request) {.async.} = | ||
if req.reqMethod == HttpGet: | ||
let path = req.url.path | ||
|
||
case path | ||
of "/": | ||
await req.responce(Http200, content, HTML) | ||
|
||
else: | ||
await req.responce(Http404, "Not Found") | ||
|
||
waitFor server.serve(Port(port), cb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@python | ||
def run(): | ||
import http.server | ||
import socketserver | ||
|
||
with socketserver.TCPServer( | ||
("127.0.0.1", 8000), http.server.SimpleHTTPRequestHandler | ||
) as httpd: | ||
httpd.serve_forever() | ||
print("Server Launched🚀") |