Skip to content

Commit

Permalink
Proxy almost there.
Browse files Browse the repository at this point in the history
  • Loading branch information
silviogutierrez committed Jul 6, 2018
1 parent a0fe953 commit d2b149d
Show file tree
Hide file tree
Showing 7 changed files with 2,465 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
.coverage
node_modules
5 changes: 3 additions & 2 deletions components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface Props {
}

export const Form = (props: Props) => {
return <div>
return <form method="GET" action="">
{props.form.map(field => <Widget key={field.widget.name} widget={field.widget} />)}
</div>;
<button type="submit">Submit</button>
</form>;
};
28 changes: 20 additions & 8 deletions components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ interface TextInput extends BaseWidget {

type Optgroup = [
null,
{
name: string;
value: string|number|boolean|null;
label: string;
selected: boolean;
},
[
{
name: string;
// value: string|number|boolean|null;
value: string|number|null;
label: string;
selected: boolean;
}
],
number
]

Expand Down Expand Up @@ -58,13 +61,22 @@ export const Widget = (props: Props) => {

switch (widget.template_name) {
case "django/forms/widgets/select.html": {
/*
if (isMultiple(widget)) {
return <div>I am a select multiple</div>;
}
return <div>I am a select single</div>;
*/
// return <div>I am a select single</div>;
const value = isMultiple(widget) ? widget.value : (widget.value[0] || '');
return <select name={widget.name} multiple={isMultiple(widget)} defaultValue={value}>
{widget.optgroups.map((optgroup, index) =>
<option key={index} value={optgroup[1][0].value || []}>{optgroup[1][0].label}</option>
)}
</select>;
}
case "django/forms/widgets/text.html": {
return <div>I am a text</div>;
return <input defaultValue={widget.value || ""} name={widget.name} />;
// return <div>I am a text</div>;
}
default: {
const _exhaustiveCheck: never = widget;
Expand Down
12 changes: 11 additions & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import React from 'react';
import axios from 'axios';
import express from 'express';
import ReactDOMServer from 'react-dom/server';
import proxy from 'http-proxy-middleware';

const app = express();

const ssrProxy = proxy({target: 'http://localhost:8000/', changeOrigin: true})

app.use('/', ssrProxy);

/*
app.get('/', async (req, res) => {
const response = await axios.get('http://localhost:8000/form/');
const config = {
params: req.query,
};
const response = await axios.get('http://localhost:8000/form/', config);
if (req.query.raw) {
res.send(response.data);
Expand All @@ -19,5 +28,6 @@ app.get('/', async (req, res) => {
}
});
*/

app.listen(3000, () => console.log('Example app listening on port 3000!'));
Loading

0 comments on commit d2b149d

Please sign in to comment.