Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to TypeScript #7

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions XArcade XInput/RestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void Stop () {
}

static public void SetCORSHeaders (IHttpContext ctx) {
ctx.Response.Headers["Access-Control-Allow-Origin"] = "*";
ctx.Response.AddHeader("Access-Control-Allow-Origin", "*");
ctx.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
}

static public void SendTextResponse (IHttpContext ctx, string response) {
Expand All @@ -67,6 +68,21 @@ static public Dictionary<string, object> ParseJson (string json) {

[RestResource]
class DefaultRestResource {
[RestRoute(HttpMethod = HttpMethod.OPTIONS, PathInfo = @"^.*?$")]
public IHttpContext CorsOptions(IHttpContext ctx) {
var validMethods = new HttpMethod[] {
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.DELETE,
HttpMethod.OPTIONS,
};
ctx.Response.Headers["Access-Control-Allow-Methods"] = string.Join(", ", validMethods.Select(x => x.ToString()));

RestServer.SetCORSHeaders(ctx);
RestServer.CloseResponse(ctx);
return ctx;
}

[RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "/")]
public IHttpContext Index (IHttpContext ctx) {
string prefix = ctx.Server.PublicFolder.Prefix;
Expand Down Expand Up @@ -159,19 +175,6 @@ public IHttpContext KeyboardSetMapping (IHttpContext ctx) {
return ctx;
}

[RestRoute(HttpMethod = HttpMethod.OPTIONS, PathInfo = "/api/keyboard/mapping")]
public IHttpContext KeyboardMappingOptions (IHttpContext ctx) {
var validMethods = new HttpMethod[] {
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.DELETE,
HttpMethod.OPTIONS,
};
ctx.Response.Headers["Access-Control-Allow-Methods"] = string.Join(", ", validMethods.Select(x => x.ToString()));
RestServer.SetCORSHeaders(ctx);
RestServer.CloseResponse(ctx);
return ctx;
}

[RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "/api/keyboard/mapping")]
public IHttpContext KeyboardDeleteMapping (IHttpContext ctx) {
Expand Down
4 changes: 2 additions & 2 deletions script/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
REM Build webapp
rd /S /Q webapp\build\
pushd webapp\
call yarn install
call yarn run build
call npm install
call node_modules\.bin\react-scripts-ts build
popd

REM Grab Scp Driver Installer
Expand Down
186 changes: 186 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
swagger: '2.0'

info:
version: '1.0.0'
title: XArcade XInput Rest API

host: 10.0.1.2:32123
schemes:
- http
basePath: /api
consumes:
- application/json

tags:
- name: keyboard
description: Keyboard mapping and service
- name: controller
description: Add / remove fake controllers

paths:
/keyboard/start:
post:
summary: Start watching keyboard for input
tags:
- keyboard
consumes:
- application/json
responses:
200:
description: Ok

/keyboard/stop:
post:
summary: Stop watching keyboard for input
tags:
- keyboard
responses:
200:
description: Ok

/keyboard/mapping:
get:
tags:
- keyboard
summary: Get keyboard mapping list and status
responses:
200:
description: Ok
schema:
type: object
properties:
currentMapping:
type: string
mappings:
type: object
additionalProperties:
type: string
example:
Mapping 1: '{ "Space": [0, "A"] }'
Mapping 2: '{ "Space": [0, "X"] }'

post:
summary: Update a mapping
tags:
- keyboard
parameters:
- name: body
in: body
schema:
type: object
properties:
name:
type: string
description: Mapping name
mapping:
type: string
description: JSON contents of mapping
responses:
200:
description: Ok
500:
description: Error
schema:
$ref: '#/definitions/BasicError'

delete:
summary: Delete a mapping
tags:
- keyboard
parameters:
- name: body
in: body
schema:
type: string
description: Name of mapping to delete
responses:
200:
description: Ok
500:
description: Error
schema:
$ref: '#/definitions/BasicError'

/keyboard/mapping/current:
post:
summary: Change mapping
tags:
- keyboard
parameters:
- name: body
in: body
schema:
type: string
description: Name of mapping to switch to
responses:
200:
description: Ok
500:
description: Error
schema:
$ref: '#/definitions/BasicError'

/keyboard/mapping/rename:
post:
summary: Rename a mapping
tags:
- keyboard
parameters:
- name: body
in: body
schema:
type: object
properties:
name:
type: string
newName:
type: string
responses:
200:
description: Ok
500:
description: Error
schema:
$ref: '#/definitions/BasicError'

/controller/start:
post:
summary: Add fake controllers
tags:
- controller
responses:
200:
description: Ok

/controller/stop:
post:
summary: Remove fake controllers
tags:
- controller
responses:
200:
description: Ok

/status:
get:
summary: Get running status
responses:
200:
description: Ok
schema:
type: object
properties:
isControllerRunning:
type: boolean
isKeyboardRunning:
type: boolean
hostname:
type: string

definitions:
BasicError:
type: object
properties:
error:
type: string
description: Error message
9 changes: 9 additions & 0 deletions webapp/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
1 change: 0 additions & 1 deletion webapp/.eslintrc

This file was deleted.

7 changes: 5 additions & 2 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

34 changes: 34 additions & 0 deletions webapp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"sourceMaps": true,
"port": 9241,
"showAsyncStacks": true,
"url": "http://localhost:3000"
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"sourceMaps": true,
"port": 9241,
"showAsyncStacks": true
},
{
"type": "node",
"request": "attach",
"name": "Attch to Tests (:9243)",
"restart": true,
"sourceMaps": true,
"showAsyncStacks": true,
"port": 9243
}
]
}
Loading