stack/packages/stack-server/src/server.ts
Zai Shi 66f6c86ddf
Basic Unit Tests (#15)
* added basic api testing framework

* added credential signup test

* added current user test

* added github action

* fixed bugs in action file

* updated action

* added pnpm setup

* added dependency install

* updated pnpm lock

* only run server tests

* added new package for e2e test

* removed unused tests

* updated action

* updated test command

* added env var reading

* fixed typo

* fixed typo

* fixed unit tests with staging

* added delay e2e test

* added start server to action

* fixed typo

* fix aciton

* updated github action

* fixed bugs

* fixed eslint error
2024-04-24 14:24:56 +02:00

26 lines
704 B
TypeScript

// server.js
import { Server, createServer } from 'http';
import next from 'next';
const app = next({ dev: true });
const handle = app.getRequestHandler();
let serverInstance: Server | null = null;
export function startServer(port: number) {
return app.prepare().then(() => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const server = createServer((req, res) => handle(req, res).catch((err) => console.error(err)));
serverInstance = server.listen(port);
console.log(`> Ready on http://localhost:${port}`);
return server;
});
}
export function stopServer() {
if (serverInstance) {
serverInstance.close();
console.log('> Server stopped');
}
}