Skip to content

Commit 443026e

Browse files
committed
fix: feedbacks architecture
1 parent 3eee489 commit 443026e

20 files changed

+415
-429
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { createRoot } from 'react-dom/client'
22
import { App } from './App'
33

4-
const rootElement =
5-
document.getElementById('root') || document.createElement('div')
4+
const rootElement = document.getElementById('root')!
65

76
const root = createRoot(rootElement)
87
root.render(<App />)
File renamed without changes.

src/client/tsconfig.json renamed to client/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020
"noFallthroughCasesInSwitch": true
2121
},
2222
"include": ["**/*"],
23-
"exclude": ["dist"]
2423
}
File renamed without changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dev:start": "fastify start --ignore-watch=.ts$ -l info -P dist/app.js",
1717
"test": "npm run db:seed && tap --jobs=1 test/**/*",
1818
"standalone": "node --env-file=.env dist/server.js",
19-
"lint": "eslint src --ignore-pattern='src/client/dist'",
19+
"lint": "eslint test src client vite.config.js",
2020
"lint:fix": "npm run lint -- --fix",
2121
"db:migrate": "node --env-file=.env scripts/migrate.js",
2222
"db:seed": "node --env-file=.env scripts/seed-database.js"

src/app.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function serviceApp (
2020
fastify: FastifyInstance,
2121
opts: FastifyPluginOptions
2222
) {
23-
const { avoidViteRegistration = true } = opts
23+
const { registerVite = true } = opts
2424

2525
// This loads all external plugins defined in plugins/external
2626
// those should be registered first as your custom plugins might depend on them
@@ -93,38 +93,27 @@ export default async function serviceApp (
9393
}
9494
)
9595

96-
await handleVite(fastify, {
97-
register: !avoidViteRegistration
98-
})
99-
}
96+
if (registerVite) {
97+
/* c8 ignore start - We don't launch the spa tests with the api tests */
98+
// We setup the SPA
99+
await fastify.register(fastifyVite, function (fastify) {
100+
return {
101+
root: path.resolve(import.meta.dirname, '../'),
102+
dev: fastify.config.FASTIFY_VITE_DEV_MODE,
103+
spa: true
104+
}
105+
})
100106

101-
async function handleVite (
102-
fastify: FastifyInstance,
103-
{ register }: { register: boolean }
104-
) {
105-
if (!register) {
106107
// Route must match vite "base": https://vitejs.dev/config/shared-options.html#base
108+
fastify.get('/', (req, reply) => {
109+
return reply.html()
110+
})
111+
112+
await fastify.vite.ready()
113+
/* c8 ignore end */
114+
} else {
107115
fastify.get('/', () => {
108116
return 'Vite is not registered.'
109117
})
110-
111-
return
112118
}
113-
/* c8 ignore start - We don't launch the spa tests with the api tests */
114-
// We setup the SPA
115-
await fastify.register(fastifyVite, function (fastify) {
116-
return {
117-
root: path.resolve(import.meta.dirname, '../'),
118-
dev: fastify.config.FASTIFY_VITE_DEV_MODE,
119-
spa: true
120-
}
121-
})
122-
123-
// Route must match vite "base": https://vitejs.dev/config/shared-options.html#base
124-
fastify.get('/', (req, reply) => {
125-
return reply.html()
126-
})
127-
128-
await fastify.vite.ready()
129-
/* c8 ignore end */
130119
}

test/app/cors.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { it } from "node:test";
2-
import { build } from "../helper.js";
3-
import assert from "node:assert";
1+
import { it } from 'node:test'
2+
import { build } from '../helper.js'
3+
import assert from 'node:assert'
44

5-
it("should correctly handle CORS preflight requests", async (t) => {
6-
const app = await build(t);
5+
it('should correctly handle CORS preflight requests', async (t) => {
6+
const app = await build(t)
77

8-
const res = await app.inject({
9-
method: "OPTIONS",
10-
url: "/",
11-
headers: {
12-
"Origin": "http://example.com",
13-
"Access-Control-Request-Method": "GET",
14-
"Access-Control-Request-Headers": "Content-Type"
15-
}
16-
});
8+
const res = await app.inject({
9+
method: 'OPTIONS',
10+
url: '/',
11+
headers: {
12+
Origin: 'http://example.com',
13+
'Access-Control-Request-Method': 'GET',
14+
'Access-Control-Request-Headers': 'Content-Type'
15+
}
16+
})
1717

18-
assert.strictEqual(res.statusCode, 204);
19-
assert.strictEqual(res.headers['access-control-allow-methods'], 'GET, POST, PUT, DELETE');
20-
});
18+
assert.strictEqual(res.statusCode, 204)
19+
assert.strictEqual(res.headers['access-control-allow-methods'], 'GET, POST, PUT, DELETE')
20+
})

test/app/error-handler.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { it } from "node:test";
2-
import assert from "node:assert";
3-
import fastify from "fastify";
4-
import serviceApp from "../../src/app.ts";
5-
import fp from "fastify-plugin";
1+
import { it } from 'node:test'
2+
import assert from 'node:assert'
3+
import fastify from 'fastify'
4+
import serviceApp from '../../src/app.ts'
5+
import fp from 'fastify-plugin'
66

7-
it("should call errorHandler", async (t) => {
8-
const app = fastify();
9-
await app.register(fp(serviceApp));
7+
it('should call errorHandler', async (t) => {
8+
const app = fastify()
9+
await app.register(fp(serviceApp))
1010

11-
app.get("/error", () => {
12-
throw new Error("Kaboom!");
13-
});
11+
app.get('/error', () => {
12+
throw new Error('Kaboom!')
13+
})
1414

15-
await app.ready();
15+
await app.ready()
1616

17-
t.after(() => app.close());
17+
t.after(() => app.close())
1818

1919
const res = await app.inject({
20-
method: "GET",
21-
url: "/error"
22-
});
20+
method: 'GET',
21+
url: '/error'
22+
})
2323

2424
assert.deepStrictEqual(JSON.parse(res.payload), {
25-
message: "Internal Server Error"
26-
});
27-
});
25+
message: 'Internal Server Error'
26+
})
27+
})

0 commit comments

Comments
 (0)