Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,4 @@ archives
.http
.vercel
.netlify
examples/with-vercel/api
examples/with-vercel/vercel.json
.DS_Store
Binary file added examples/with-entries/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/with-entries/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ingest-with-entries",
"version": "1.0.0",
"description": "A simple boilerplate for using Ingest with plugins.",
"private": true,
"plugins": [
"./src/plugin"
],
"scripts": {
"build": "tsc",
"dev": "ts-node src/scripts/serve.ts"
},
"dependencies": {
"@stackpress/ingest": "0.3.6"
},
"devDependencies": {
"@types/node": "22.9.3",
"ts-node": "10.9.2",
"typescript": "5.7.2"
}
}
24 changes: 24 additions & 0 deletions examples/with-entries/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CookieOptions } from '@stackpress/ingest';

export const environment = process.env.SERVER_ENV || 'development';
export const config: Config = {
server: {
cwd: process.cwd(),
mode: environment,
bodySize: 0
},
cookie: { path: '/' },
body: { size: 0 }
};

export type Config = {
server: {
cwd: string,
mode: string,
bodySize: number
},
cookie: CookieOptions,
body: {
size: number
}
};
3 changes: 3 additions & 0 deletions examples/with-entries/src/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function ShouldNotWork(message: string) {
throw new Error(message);
};
14 changes: 14 additions & 0 deletions examples/with-entries/src/events/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ServerRequest, Response } from '@stackpress/ingest';

export default function Error(req: ServerRequest, res: Response) {
const html = [ `<h1>${res.error}</h1>` ];
const stack = res.stack?.map((log, i) => {
const { line, char } = log;
const method = log.method.replace(/</g, "&lt;").replace(/>/g, "&gt;");
const file = log.file.replace(/</g, "&lt;").replace(/>/g, "&gt;");
return `#${i + 1} ${method} - ${file}:${line}:${char}`;
}) || [];
html.push(`<pre>${stack.join('<br><br>')}</pre>`);

res.setHTML(html.join('<br>'));
}
34 changes: 34 additions & 0 deletions examples/with-entries/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { HTTPServer } from '@stackpress/ingest';
import type { Config } from './config';

import path from 'path';
import { config } from './config';

export default function plugin(server: HTTPServer<Config>) {
server.config.set(config);

server.get('/', path.join(__dirname, 'routes/home'));
server.get('/login', path.join(__dirname, 'routes/login'));

server.get('/user', path.join(__dirname, 'routes/user/search'));
server.post('/user', path.join(__dirname, 'routes/user/create'));
server.get('/user/:id', path.join(__dirname, 'routes/user/detail'));
server.put('/user/:id', path.join(__dirname, 'routes/user/update'));
server.delete('/user/:id', path.join(__dirname, 'routes/user/remove'));

server.get('/redirect', path.join(__dirname, 'routes/redirect'));
server.get('/icon.png', path.join(__dirname, 'routes/icon'));
server.get('/stream', path.join(__dirname, 'routes/stream'));
server.get('/__sse__', path.join(__dirname, 'routes/sse'));

server.get('/error', path.join(__dirname, 'routes/error'));
server.get('/catch', path.join(__dirname, 'routes/catch'));
server.get('/**', path.join(__dirname, 'routes/404'));

server.on('error', path.join(__dirname, 'events/error'));

server.register('project', { welcome: 'Hello, World!!' });
server.on('request', (req, res) => {
console.log('Request:', req.url);
});
}
8 changes: 8 additions & 0 deletions examples/with-entries/src/routes/404.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ServerRequest, Response } from '@stackpress/ingest';

export default function NotFound(req: ServerRequest, res: Response) {
if (!res.code && !res.status && !res.sent) {
//send the response
res.setHTML('Not Found');
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response, Exception } from '@stackpress/ingest';
import { ServerRequest, Response, Exception } from '@stackpress/ingest';

export default function ErrorResponse(req: Context, res: Response) {
export default function ErrorResponse(req: ServerRequest, res: Response) {
try {
throw Exception.for('Not implemented');
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions examples/with-entries/src/routes/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ServerRequest, Response } from '@stackpress/ingest';
import Error from '../error';

export default function ErrorResponse(req: ServerRequest, res: Response) {
Error('Not implemented');
};
6 changes: 6 additions & 0 deletions examples/with-entries/src/routes/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ServerRequest, Response } from '@stackpress/ingest';

export default async function HomePage(req: ServerRequest, res: Response) {
const project = req.context.plugin<{ welcome: string }>('project');
res.setHTML(project.welcome);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default async function Icon(req: Context, res: Response) {
export default async function Icon(req: ServerRequest, res: Response) {
if (res.code || res.status || res.body) return;
const file = path.resolve(process.cwd(), 'icon.png');
if (fs.existsSync(file)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

const template = `
<!DOCTYPE html>
Expand All @@ -19,7 +19,7 @@ const template = `
</html>
`;

export default function Login(req: Context, res: Response) {
export default function Login(req: ServerRequest, res: Response) {
//send the response
res.setHTML(template.trim());
};
5 changes: 5 additions & 0 deletions examples/with-entries/src/routes/redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ServerRequest, Response } from '@stackpress/ingest';

export default function Redirect(req: ServerRequest, res: Response) {
res.redirect('/user');
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default async function SSE(req: Context, res: Response) {
export default async function SSE(req: ServerRequest, res: Response) {
res.headers
.set('Cache-Control', 'no-cache')
.set('Content-Encoding', 'none')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

const template = `
<!DOCTYPE html>
Expand All @@ -21,7 +21,7 @@ const template = `
</html>
`;

export default function Stream(req: Context, res: Response) {
export default function Stream(req: ServerRequest, res: Response) {
//send the response
res.setHTML(template.trim());
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

let id = 0;

export default function UserCreate(req: Context, res: Response) {
export default function UserCreate(req: ServerRequest, res: Response) {
//get form body
const form = req.data();
//maybe insert into database?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default function UserDetail(req: Context, res: Response) {
export default function UserDetail(req: ServerRequest, res: Response) {
//get params
const id = parseInt(req.data('id') || '');
if (!id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default function UserRemove(req: Context, res: Response) {
export default function UserRemove(req: ServerRequest, res: Response) {
//get params
const id = parseInt(req.data('id') || '');
if (!id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default function UserSearch(req: Context, res: Response) {
export default function UserSearch(req: ServerRequest, res: Response) {
//get filters
//const filters = req.query.get<Record<string, unknown>>('filter');
//maybe get from database?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Response } from '@stackpress/ingest';
import { ServerRequest, Response } from '@stackpress/ingest';

export default function UserUpdate(req: Context, res: Response) {
export default function UserUpdate(req: ServerRequest, res: Response) {
//get params
const id = parseInt(req.data('id') || '');
if (!id) {
Expand Down
13 changes: 13 additions & 0 deletions examples/with-entries/src/scripts/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import server from '../server';

async function main() {
//load the plugins
await server.bootstrap();
//start the server
server.create().listen(3000, () => {
console.log('Server is running on port 3000');
console.log('------------------------------');
});
};

main().catch(console.error);
10 changes: 10 additions & 0 deletions examples/with-entries/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//types
import type { Config } from './config';
//ingest
import { server } from '@stackpress/ingest/http';
//local
import { environment } from './config';

export default server<Config>({
cache: environment === 'production'
});
12 changes: 5 additions & 7 deletions examples/with-fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "ingest-with-vercel",
"name": "ingest-with-fetch",
"version": "1.0.0",
"description": "A simple boilerplate for using Ingest with Vercel.",
"description": "A simple boilerplate for using Ingest with fetch API.",
"private": true,
"scripts": {
"generate": "yarn build:tsc && yarn build:files",
"build:tsc": "tsc",
"build:files": "ts-node src/scripts/build.ts",
"dev": "ts-node src/scripts/server.ts"
"build": "tsc",
"dev": "ts-node src/server.ts"
},
"dependencies": {
"@stackpress/ingest-vercel": "0.2.14"
"@stackpress/ingest": "0.3.6"
},
"devDependencies": {
"@types/node": "22.9.3",
Expand Down
2 changes: 0 additions & 2 deletions examples/with-fetch/plugin.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion examples/with-fetch/plugin.js

This file was deleted.

4 changes: 0 additions & 4 deletions examples/with-fetch/src/build.ts

This file was deleted.

22 changes: 0 additions & 22 deletions examples/with-fetch/src/routes.ts

This file was deleted.

8 changes: 0 additions & 8 deletions examples/with-fetch/src/routes/404.ts

This file was deleted.

14 changes: 0 additions & 14 deletions examples/with-fetch/src/routes/error.ts

This file was deleted.

9 changes: 0 additions & 9 deletions examples/with-fetch/src/routes/home.ts

This file was deleted.

Loading
Loading