Skip to content

Commit f39a132

Browse files
committed
feat: first go - doesn't work
1 parent dfdafe2 commit f39a132

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/server/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "poor-clares-arundel-koa-server",
33
"version": "1.0.0",
4+
"type": "module",
45
"scripts": {
56
"build": "tsc",
67
"dev:build": "pnpm run build && pnpm run client",

src/server/src/index.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import Koa from 'koa';
22
import helmet from 'koa-helmet';
3+
// import koaLogger from 'koa-logger';
34
import send from 'koa-send';
45
import serve from 'koa-static';
5-
import path from 'path';
6+
import * as path from 'path';
67
import * as appInsights from 'applicationinsights';
78

8-
import { config } from './config';
9-
import { logger } from './logging';
10-
import { routes } from './routes/index';
9+
import { config } from './config.js';
10+
import { logger } from './logging.js';
11+
import { routes } from './routes/index.js';
12+
13+
// const stripAnsi = await import('strip-ansi');
1114

1215
if (config.appInsightsConnectionString) {
1316
appInsights
@@ -21,8 +24,9 @@ if (config.appInsightsConnectionString) {
2124

2225
const app = new Koa();
2326

27+
// app.use(koaLogger((text) => stripAnsi(text)));
2428
app.use(
25-
helmet.contentSecurityPolicy({
29+
helmet.default.contentSecurityPolicy({
2630
useDefaults: true,
2731
directives: {
2832
scriptSrc: ["'self'", "'unsafe-inline'", 'storage.googleapis.com', 'www.google-analytics.com'],
@@ -33,7 +37,7 @@ app.use(
3337
app.use(logger);
3438
app.use(routes);
3539

36-
const publicPath = path.join(__dirname, '..', 'client', 'dist');
40+
const publicPath = path.join(path.dirname(import.meta.url), '..', 'client', 'dist');
3741

3842
app.use(serve(publicPath));
3943
app.use(async (ctx) => {

src/server/src/logging.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Koa from 'koa';
2-
import { config } from './config';
2+
import { config } from './config.js';
33

44
interface ILogData {
55
method: string;

src/server/src/routes/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { koaBody } from 'koa-body';
22
import Router from 'koa-router';
33

4-
import { prayerRequestPOST } from './prayerRequestPOST';
5-
import { statusGET } from './statusGET';
4+
import { prayerRequestPOST } from './prayerRequestPOST.js';
5+
import { statusGET } from './statusGET.js';
66

77
const router = new Router();
88

src/server/src/routes/prayerRequestPOST.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import FormData from 'form-data';
22
import Router from 'koa-router';
3-
import Mailgun from 'mailgun.js';
3+
import mgjs from 'mailgun.js';
44

5-
import { config } from '../config';
5+
import { config } from '../config.js';
66

77
export function prayerRequestPOST(): Router.IMiddleware<unknown, unknown> {
88
return async (ctx, _next) => {
@@ -23,7 +23,7 @@ export function prayerRequestPOST(): Router.IMiddleware<unknown, unknown> {
2323

2424
// We pass the api_key and domain to the wrapper, or it won't be able to identify + send emails
2525
// const mailgun = new Mailgun({ apiKey, domain });
26-
const mailgun = new Mailgun(FormData);
26+
const mailgun = new mgjs.default(FormData);
2727
const mg = mailgun.client({ username: 'api', key: config.apiKey });
2828

2929
const prayerRequest = {

src/server/src/routes/statusGET.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Router from 'koa-router';
22

3-
import { config } from '../config';
3+
import { config } from '../config.js';
44

55
export function statusGET(): Router.IMiddleware<unknown, unknown> {
66
return async (ctx, _next) => {

src/server/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"compilerOptions": {
33
/* Base Options: */
4-
"esModuleInterop": true,
4+
"esModuleInterop": false,
55
"skipLibCheck": true,
66
"target": "es2022",
77
"allowJs": true,
88
"resolveJsonModule": true,
99
"moduleDetection": "force",
1010
"isolatedModules": true,
11-
// "verbatimModuleSyntax": true,
11+
"verbatimModuleSyntax": true,
1212

1313
/* Strictness */
1414
"strict": true,
@@ -17,6 +17,7 @@
1717

1818
/* If transpiling with TypeScript: */
1919
"module": "NodeNext",
20+
"moduleResolution": "nodenext",
2021
"outDir": "dist",
2122
"sourceMap": true,
2223

0 commit comments

Comments
 (0)