switch to go
This commit is contained in:
parent
31ec2917ea
commit
0f34300a8a
40
Dockerfile
40
Dockerfile
|
@ -1,40 +0,0 @@
|
|||
# use the official Bun image
|
||||
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
||||
FROM docker.io/oven/bun:1 as base
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# install dependencies into temp directory
|
||||
# this will cache them and speed up future builds
|
||||
FROM base AS install
|
||||
RUN mkdir -p /temp/dev
|
||||
COPY package.json bun.lockb /temp/dev/
|
||||
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||
|
||||
# install with --production (exclude devDependencies)
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package.json bun.lockb /temp/prod/
|
||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||
|
||||
# copy node_modules from temp directory
|
||||
# then copy all (non-ignored) project files into the image
|
||||
FROM install AS prerelease
|
||||
COPY --from=install /temp/dev/node_modules node_modules
|
||||
COPY . .
|
||||
|
||||
# [optional] tests & build
|
||||
ENV NODE_ENV=production
|
||||
RUN bun test
|
||||
RUN bun run build
|
||||
|
||||
# copy production dependencies and source code into final image
|
||||
FROM base AS release
|
||||
COPY --from=install /temp/prod/node_modules node_modules
|
||||
COPY --from=prerelease /usr/src/app/index.ts .
|
||||
COPY --from=prerelease /usr/src/app/package.json .
|
||||
|
||||
# run the app
|
||||
USER bun
|
||||
EXPOSE 8000/tcp
|
||||
EXPOSE 8080/tcp
|
||||
ENTRYPOINT [ "bun", "run", "index.ts" ]
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
in {
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
bun
|
||||
go
|
||||
mpd
|
||||
mpc-cli
|
||||
];
|
||||
|
|
21
package.json
21
package.json
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"name": "sanic",
|
||||
"module": "server.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "bun run server.ts",
|
||||
"init": "mkdir -p /tmp/sanic/{music,playlists}; touch /tmp/sanic/mpd_db",
|
||||
"mpd": "mpd --no-daemon ./mpd.conf",
|
||||
"docker-build": "docker build --pull -t sanic .",
|
||||
"docker-run": "docker run -it --rm -p 8000:8000 -p 8080:8080 sanic"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bun-types": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0"
|
||||
}
|
||||
}
|
32
server.ts
32
server.ts
|
@ -1,32 +0,0 @@
|
|||
// Run websocket server
|
||||
const wsServer = Bun.serve({
|
||||
port: 8080,
|
||||
fetch(req, server) {
|
||||
// upgrade the request to a WebSocket
|
||||
if (server.upgrade(req)) {
|
||||
return; // do not return a Response
|
||||
}
|
||||
return new Response("Upgrade failed :(", { status: 500 });
|
||||
},
|
||||
websocket: {
|
||||
message(ws, message) { // a message is received
|
||||
ws.send(message); // echo back the message
|
||||
},
|
||||
open(ws) {}, // a socket is opened
|
||||
close(ws, code, message) {}, // a socket is closed
|
||||
drain(ws) {}, // the socket is ready to receive more data
|
||||
},
|
||||
});
|
||||
|
||||
// Run web server
|
||||
const webServer = Bun.serve({
|
||||
port: 8000,
|
||||
//unix: "/run/sanic.sock",
|
||||
fetch(req) {
|
||||
return new Response("Put frontend here!");
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Listening on http://localhost:${webServer.port} ...`);
|
||||
console.log(`Listening on ws://localhost:${wsServer.port} ...`);
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleDetection": "force",
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"composite": true,
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue