Socekt server
This commit is contained in:
parent
c751f4c5e7
commit
7b70be5e6e
24
BUILD.ps1
24
BUILD.ps1
@ -2,14 +2,22 @@
|
||||
## PSVersionTable.PSVersion
|
||||
## winget install --id Microsoft.Powershell --source winget
|
||||
|
||||
mkdir dist
|
||||
cd webapp
|
||||
npm run build
|
||||
cp -r .next/static .next/standalone/gitea/CoffeeChat/webapp/.next
|
||||
mkdir dist
|
||||
cp -r .next/standalone/gitea/CoffeeChat/webapp/* dist
|
||||
Compress-Archive -Path .\dist\* -DestinationPath ..\dist\client-dist.zip -Force
|
||||
Remove-Item dist -Recurse -Force
|
||||
# mkdir dist
|
||||
# cd webapp
|
||||
# npm run build
|
||||
# cp -r .next/static .next/standalone/gitea/CoffeeChat/webapp/.next
|
||||
# mkdir dist
|
||||
# cp -r .next/standalone/gitea/CoffeeChat/webapp/* dist
|
||||
# Compress-Archive -Path .\dist\* -DestinationPath ..\dist\client-dist.zip -Force
|
||||
# Remove-Item dist -Recurse -Force
|
||||
# cd ..
|
||||
# cd .\coffeechat\
|
||||
# $env:JAVA_HOME="C:\Program Files\Java\jdk-17";mvn clean package
|
||||
# cd ..
|
||||
# copy coffeechat\target\coffeechat-0.0.1-SNAPSHOT.jar dist
|
||||
cd serverWS
|
||||
node --experimental-sea-config sea-config.json
|
||||
mv .\socket-server ..\dist\
|
||||
cd ..
|
||||
# cd dist
|
||||
# npm publish
|
||||
|
||||
26
README.md
Normal file
26
README.md
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
java -jar myapp.jar --spring.config.location=file:/path/to/custom.properties
|
||||
java -jar coffeechat-0.0.1-SNAPSHOT.jar --spring.config.import=file:/var/www/CC/application.properties
|
||||
|
||||
Sample properies
|
||||
|
||||
spring.application.name=Coffee Chat
|
||||
server.port=8081
|
||||
logging.level.root=DEBUG
|
||||
# Database properties
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/coffeeChat
|
||||
spring.datasource.username=coffeeChat
|
||||
spring.datasource.password=coffeeChat
|
||||
|
||||
# JPA/Hibernate settings (optional but useful)
|
||||
# 'update' automatically updates the database schema based on your entities
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
jwt.secret=your_secret_key_heretjldjfgljfdsigjj9psejgjsidgjscgtj
|
||||
jwt.expiration=3600000
|
||||
|
||||
Client
|
||||
|
||||
export "PORT=4050"; node server.js
|
||||
@ -1,44 +0,0 @@
|
||||
package za.co.rootbranch.coffeechat;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import za.co.rootbranch.coffeechat.models.User;
|
||||
import za.co.rootbranch.coffeechat.repositories.UserRepository;
|
||||
import za.co.rootbranch.coffeechat.services.UserService;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CreateUserTest {
|
||||
|
||||
@Mock
|
||||
private UserRepository userRepository;
|
||||
|
||||
@InjectMocks
|
||||
private UserService userService;
|
||||
|
||||
@BeforeEach()
|
||||
void init() {
|
||||
// do setup
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestCreateANewUser() {
|
||||
// Mock the behavior of the repository
|
||||
String email = "test@example.com";
|
||||
User mockUser = new User(null,"", "", email);
|
||||
when(userRepository.findByEmail(email)).thenReturn(mockUser); // Stub the method call
|
||||
|
||||
// Call the service method
|
||||
User foundUser = userService.findUserByEmail(email);
|
||||
|
||||
// Verify the result using JUnit assertions
|
||||
assertEquals(email, foundUser.getEmail());
|
||||
}
|
||||
}
|
||||
BIN
dist/client-dist.zip
vendored
BIN
dist/client-dist.zip
vendored
Binary file not shown.
BIN
dist/coffeechat-0.0.1-SNAPSHOT.jar
vendored
Normal file
BIN
dist/coffeechat-0.0.1-SNAPSHOT.jar
vendored
Normal file
Binary file not shown.
BIN
dist/socket-server
vendored
Normal file
BIN
dist/socket-server
vendored
Normal file
Binary file not shown.
41
serverWS/.gitignore
vendored
Normal file
41
serverWS/.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
35
serverWS/index.js
Normal file
35
serverWS/index.js
Normal file
@ -0,0 +1,35 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const http = require("http");
|
||||
const server = http.createServer(app);
|
||||
|
||||
const { Server } = require("socket.io");
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: "http://192.168.0.131:3000", // Replace with the origin of your client application
|
||||
methods: ["GET", "POST", "WS"], // Allowed HTTP methods
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
// res.sendFile(__dirname + "/index.html");
|
||||
res.send(`Upgrade`);
|
||||
});
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
console.log("A user connected");
|
||||
|
||||
// Handle custom events from the client
|
||||
socket.on("chat message", (msg) => {
|
||||
io.emit("chat message", msg); // Emit the message to all connected clients
|
||||
});
|
||||
|
||||
// Handle disconnections
|
||||
socket.on("disconnect", () => {
|
||||
console.log("User disconnected");
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(4000, () => {
|
||||
console.log("Listening on port 4000");
|
||||
});
|
||||
1076
serverWS/package-lock.json
generated
Normal file
1076
serverWS/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
serverWS/package.json
Normal file
6
serverWS/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"express": "^5.2.1",
|
||||
"socket.io": "^4.8.3"
|
||||
}
|
||||
}
|
||||
1
serverWS/sea-config.json
Normal file
1
serverWS/sea-config.json
Normal file
@ -0,0 +1 @@
|
||||
{ "main": "index.js", "output": "socket-server" }
|
||||
Loading…
x
Reference in New Issue
Block a user