Skip to content

Commit 9df33ca

Browse files
committed
make signup form work
1 parent a82adc2 commit 9df33ca

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

edge/components/signup.edge

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
@if(prompt === true)
33
<p class="prompt content-font">want to recieve backspin in your inbox?</p>
44
@end
5-
<form class="newsletter">
6-
<input name="newsletter" type="email" placeholder="{{ emailPlaceholder || 'cool@person.com' }}" class="purdy" required>
7-
<input name="newsletter" type="submit" value="{{ submitText || 'sign up' }}" accesskey="s" class="purdy">
5+
<form class="newsletter" action="/signup" method="POST">
6+
<input name="email" type="email" placeholder="{{ emailPlaceholder || 'cool@person.com' }}" class="purdy" required>
7+
<input name="submit" type="submit" value="{{ submitText || 'sign up' }}" accesskey="s" class="purdy">
88
</form>
99
</section>

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
"scripts": {
88
"check": "tsc --noEmit --erasableSyntaxOnly --allowImportingTsExtensions",
99
"start": "node --env-file-if-exists=.env ./src/index.ts | pino-pretty",
10-
"dev": "npm run check && portless backspin npm run start",
10+
"dev": "npm run check && npm run start",
1111
"update": "npx npm-check-updates -u",
1212
"portless:config": "portless proxy start --https"
1313
},
1414
"author": "Tierney Cyren <hello@bnb.im>",
1515
"license": "MIT",
1616
"dependencies": {
17+
"@fastify/formbody": "^8.0.2",
1718
"@fastify/view": "^11.1.1",
1819
"edge-markdown": "^1.10.0",
1920
"edge.js": "^6.5.0",
2021
"fastify": "^5.8.4",
21-
"luxon": "^3.7.2"
22+
"luxon": "^3.7.2",
23+
"pino-pretty": "^13.1.3"
2224
},
2325
"devDependencies": {
2426
"@types/luxon": "^3.7.1",
2527
"@types/node": "^25.5.0",
26-
"pino-pretty": "^13.1.3",
27-
"portless": "^0.7.2",
2828
"typescript": "^6.0.2"
2929
}
3030
}

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import { Edge } from 'edge.js'
44
import { edgeMarkdown } from 'edge-markdown'
55
import { readdir, readFile } from 'node:fs/promises'
66
import { resolve, join } from 'node:path'
7+
import { fastifyFormbody } from '@fastify/formbody'
8+
9+
const port = Number(process.env.PORT);
10+
const hostname = String(process.env.HOST);
711

812
// fastify configuration
913
const server = fastify(
1014
{ logger: true }
1115
)
1216

17+
//set up our form parsing
18+
server.register(fastifyFormbody)
19+
1320
// set up parent of the `src` directory for us to use in different imports
1421
const parentOfSrcDirectory = resolve(import.meta.dirname, '..')
1522

@@ -101,13 +108,15 @@ server.get('/health', async (request, reply) => {
101108
return { status: 'ok' }
102109
})
103110

111+
server.post('/signup', async (request: any, reply: any) => {
112+
const { email } = request.body;
113+
reply.send({ email });
114+
})
115+
104116
// run the server
105117
const start = async () => {
106-
const port = Number(process.env.PORT);
107-
const host = String(process.env.HOST);
108-
109118
try {
110-
await server.listen({ port, host });
119+
await server.listen({ port, host: hostname });
111120
} catch (err) {
112121
server.log.error(err)
113122
process.exit(1)

0 commit comments

Comments
 (0)